Access violation reading from text file

Hello all,

I have written a program to read strings from a text file. The text file is very brief and the fscanf functions seem to be reading the blank parts of the file as some type of junk characters when I look in the variables inspector in the debug mode. The characters are like Í. So Visual C++ produces an Access Violation when the fscanf statements get past the text in the file. How do I avoid this? Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fseek(g,0,SEEK_SET);

	while(!feof(g))
	{
		fscanf(g,"%s",&outbuf);
		fscanf(g,"%d",&indox);
		fscanf(g,"%d",&tally);
		fscanf(g,"%s",&alignchar);
		alignstr = alignchar;
		

		if(alignstr.compare("NN")!=0)
		{cout<<"Misalignment!";
		}
	
		temp = outbuf;
.
.
.
}



Last edited on
Nobody willing to help?
You maybe mis-interpreting the what you see.
Those funny characters are not put there by the fscanf function, they
are set deliberately by Visual C++.
In debugging mode - Microsoft Visual C++ tracks uninitialsed variables.
and it uses this funny character Í to show that. (actuall decimal value 204)

If you are looking at the file pointer in the variables window, you should see the actual data of the file
followed by these characters. These are the rubbish beyond the End Of File mark and therefore will not be read by fscanf.

If you see these characters in a variable in the debug window it means that the variable is uninitialised.

Í = 204 decimal = CC hex - so VisualC++ will set an unitialised integer to 0xCCCC
You may also see 0xCD used.
Last edited on
Topic archived. No new replies allowed.