Hello,
I'm a novice programmer working on file I/O. Apologies in advance if the question is simple, or if similar questions are already posted. I searched the most recent posts tagged with "file I/O" but didn't see similar entries...
That aside, I'm trying to read from a text file for a particular character or set of characters, then read the integer directly following it,
for example,
.i 2
I'd want to look for the '.i' (and there should be a space after that) then an integer. I'm trying to read the integer now, and I'd like to save it as a variable for later use
all I get are two zeros in output file for an input file of .i 2 where I'd hope to get 2.Code:for(i=1;i<3;++i) {
while((imat[i]=getc(inp))!=EOF) //input matrix of type char; inp is input file pointer
if(imat[1]=='.'&& imat[2]=='i') // look for '.i'
fscanf(inp, "%s", letternum); //letternum is array of length 1; char letternum[1]
num = atoi(letternum); //convert string letternum to integer
fprintf(outp, "%d\n",num); //print integer in file to see what is being read
}
Anyone able to give me an idea of how I can read the 2 following a .i?
Much appreciation