Yes, the maxiumum length of a file will be 60 rows.
However, my program will not compile at this section
there are too many arguments to function fgets.Code:while (fgets(line,8,8,fh)!=NULL) {
Printable View
Also using
I am sure that it recognises the correct number of lines in the file, but it does not store it in 'number' correctly, nor does it increment the sum either.Code:while (fscanf(fp,"%*[^\n]\n",& number)!=EOF)
sum++;
I think you've gotten turned around on what fscanf does. For one thing, the * suppresses assignment, so by definition nothing will get stored in number. (This is probably a good thing, since it will try to store a bunch of characters in that address, as opposed to a float, which I think is what number was.) Secondly sum is indeed getting incremented unless your file is empty. (No really, I just tried it here on this machine.)
Whoops! Sorry sorry sorry... I was thinking about fread(), which takes a number of chunks and a size for each chunk. fgets() just takes a size, so that should be 64 (it only reads up to 63 tho, because it leaves room for a null terminator).
fscanf() returns the number of successful "assignments" (ie, the number of variables written into), so you could try a check on that:
This will tell you whether "&number" got written into. If the answer is 0, your template does not work with your material. That's why I'm recommending fgets with sscanf, because it is FAR EASIER to make fgets work than fscanf, and you won't have to mess around with \n in the template (which I could be wrong, but I don't think that works anyway).Code:int x;
x=fscanf(.....
printf("fscanf returned %d\n",x);