J
juleigha27
Hi,
First off, I want to apologize if this already got posted it seemed
like something happened when I tried to post it previously and it
didn't work.
I am new to file manipulation with c. I am trying to read in a file
and then parse it to assign the value to variables. I have read that
fread is more is better for this then fscanf, so I tried the following
code with the input file and resulting output:
inStream = fopen("globals", "r")))
fseek(inStream,0,SEEK_END);
ulFileSize = ftell(inStream);
fseek(inStream,0,SEEK_SET);
char *pBuffer = (char *)malloc(ulFileSize+1);
memset(pBuffer, '\0',ulFileSize+1);
fread(pBuffer, ulFileSize,1, inStream);
fseek(inStream, 0, SEEK_SET);
writeLogMessage("Read copied Globals:
\n=================================");
writeLog(pBuffer, ulFileSize);
input file "globals":
g_iNumGraphs 4
<-----this is missing below
g_iNumUndef 0
g_iAnalysisUndef 0
iNumber 3163
g_szOutFilename Results61101.txt
gStart 1176399755
gFileName
genfilename ../GenDistance/GenDist3163.txt <-------this is
missing below
printed to logfile:
Read copied Globals:
=================================
g_iNumGraphs 0
g_iNumUndef 0
g_iAnalysisUndef 0
iNumber 3163
g_szOutFilename Results61101.txt
gStart 1176399755
gFileName
genfilename
What I found is that some things aren't read for instance like the 4
on the first line. I encountered similar problems with fscanf when I
attempted to implement this. I am going about this incorrectly? Can
anyone suggest a better solution? For the first line I also inserted
an additional tab and typed 4 for example:
fprintf(fp,"g_iNumGraphs\t4\t%d\n",g_iNumGraphs);
g_iNumGraphs 4 4
With fread if reads the first 4, but not the second (which was
originally written to the file as a variable)
ie This what results after fread or fscanf :
g_iNumGraphs 4 0
I would greatly appreciate any tips!
Thanks,
Jules
First off, I want to apologize if this already got posted it seemed
like something happened when I tried to post it previously and it
didn't work.
I am new to file manipulation with c. I am trying to read in a file
and then parse it to assign the value to variables. I have read that
fread is more is better for this then fscanf, so I tried the following
code with the input file and resulting output:
inStream = fopen("globals", "r")))
fseek(inStream,0,SEEK_END);
ulFileSize = ftell(inStream);
fseek(inStream,0,SEEK_SET);
char *pBuffer = (char *)malloc(ulFileSize+1);
memset(pBuffer, '\0',ulFileSize+1);
fread(pBuffer, ulFileSize,1, inStream);
fseek(inStream, 0, SEEK_SET);
writeLogMessage("Read copied Globals:
\n=================================");
writeLog(pBuffer, ulFileSize);
input file "globals":
g_iNumGraphs 4
<-----this is missing below
g_iNumUndef 0
g_iAnalysisUndef 0
iNumber 3163
g_szOutFilename Results61101.txt
gStart 1176399755
gFileName
genfilename ../GenDistance/GenDist3163.txt <-------this is
missing below
printed to logfile:
Read copied Globals:
=================================
g_iNumGraphs 0
g_iNumUndef 0
g_iAnalysisUndef 0
iNumber 3163
g_szOutFilename Results61101.txt
gStart 1176399755
gFileName
genfilename
What I found is that some things aren't read for instance like the 4
on the first line. I encountered similar problems with fscanf when I
attempted to implement this. I am going about this incorrectly? Can
anyone suggest a better solution? For the first line I also inserted
an additional tab and typed 4 for example:
fprintf(fp,"g_iNumGraphs\t4\t%d\n",g_iNumGraphs);
g_iNumGraphs 4 4
With fread if reads the first 4, but not the second (which was
originally written to the file as a variable)
ie This what results after fread or fscanf :
g_iNumGraphs 4 0
I would greatly appreciate any tips!
Thanks,
Jules