Click here to Skip to main content
15,898,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Saving to file in human readable form Pin
Michael Dunn29-Jun-06 15:44
sitebuilderMichael Dunn29-Jun-06 15:44 
QuestionNetWkstaGetInfo() Question Pin
RobJones29-Jun-06 13:23
RobJones29-Jun-06 13:23 
QuestionRe: NetWkstaGetInfo() Question Pin
David Crow30-Jun-06 2:26
David Crow30-Jun-06 2:26 
AnswerRe: NetWkstaGetInfo() Question Pin
RobJones30-Jun-06 3:29
RobJones30-Jun-06 3:29 
QuestionRe: NetWkstaGetInfo() Question Pin
David Crow30-Jun-06 3:45
David Crow30-Jun-06 3:45 
QuestionCListCtrl Notify msg Pin
ftsOne29-Jun-06 11:53
ftsOne29-Jun-06 11:53 
AnswerRe: CListCtrl Notify msg Pin
Michael Dunn29-Jun-06 15:47
sitebuilderMichael Dunn29-Jun-06 15:47 
Questionfile manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 10:06
kitty529-Jun-06 10:06 
Hi everyone! Big Grin | :-D
Here I go again...;)
I'm writing a simple win32 console program.
so, I'm trying to open a text file that has the following in it:
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x07

What I want to do is open the file then get the data and stick it into an array of CString or whatever. i.e. data[0] = 0x0, data[1] = 0x1, etc.
Here is my code:
<br />
#include "stdafx.h"<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
	char *data[200];<br />
	FILE *fpread;<br />
	int i = 0;<br />
	<br />
	if ( (fpread = fopen("data.txt", "r")) == NULL )<br />
	{<br />
		printf("Cannot open file for reading. \n");<br />
		return -1;<br />
	}<br />
<br />
        //initialize data<br />
	for ( int a = 0; a < 200; a++ )<br />
	{<br />
		data[a] = "q";<br />
	}<br />
<br />
	while( (feof(fpread) == 0 || ferror(fpread) == 0) )<br />
	{<br />
		fscanf(fpread, "%s", &data[i]); <- problem is here... i think<br />
		printf( "data = %s \n", data[i]);<br />
		i++;<br />
	}<br />
<br />
	if (feof(fpread) != 0)<br />
	{<br />
		printf("EOF\n");<br />
	}<br />
	else if (ferror(fpread) != 0)<br />
	{<br />
		printf("error!\n");<br />
	}<br />
<br />
	return 0;<br />
}<br />

When I run my code I get:
Unhandled exception at 0x0059f89f in testFileOpen.exe: 0xC0000005: Access violation reading location 0x30307830.

then it opens up the file: output.h and says that it has a problem with line 1646.

please explain....Confused | :confused:

Kitty5
AnswerRe: file manipulation with fopen(), fscanf() Pin
David Crow29-Jun-06 10:16
David Crow29-Jun-06 10:16 
GeneralRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 10:25
kitty529-Jun-06 10:25 
QuestionRe: file manipulation with fopen(), fscanf() Pin
David Crow29-Jun-06 11:32
David Crow29-Jun-06 11:32 
AnswerRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 11:37
kitty529-Jun-06 11:37 
GeneralRe: file manipulation with fopen(), fscanf() Pin
David Crow30-Jun-06 2:14
David Crow30-Jun-06 2:14 
AnswerRe: file manipulation with fopen(), fscanf() [modified] Pin
Zac Howland29-Jun-06 10:32
Zac Howland29-Jun-06 10:32 
GeneralRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 10:55
kitty529-Jun-06 10:55 
GeneralRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 11:06
Zac Howland29-Jun-06 11:06 
GeneralRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 11:19
kitty529-Jun-06 11:19 
GeneralRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 15:57
Zac Howland29-Jun-06 15:57 
QuestionRe: file manipulation with fopen(), fscanf() [modified] Pin
kitty529-Jun-06 11:55
kitty529-Jun-06 11:55 
AnswerRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 15:59
Zac Howland29-Jun-06 15:59 
AnswerRe: file manipulation with fopen(), fscanf() Pin
Stephen Hewitt29-Jun-06 18:01
Stephen Hewitt29-Jun-06 18:01 
QuestionStatic Variables [modified] Pin
Jay0329-Jun-06 8:41
Jay0329-Jun-06 8:41 
AnswerRe: Static Variables Pin
toxcct29-Jun-06 8:58
toxcct29-Jun-06 8:58 
AnswerRe: Static Variables Pin
Jun Du29-Jun-06 8:58
Jun Du29-Jun-06 8:58 
AnswerRe: Static Variables Pin
David Crow29-Jun-06 8:58
David Crow29-Jun-06 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.