I am having trouble getting my ‘do while’ loop to work. In my program I need to scan the first 4digits of a line, capture and compare those digits with the number a user entered. The program then counts how many times those 4digits appeared in the document.
My problem is I can’t seem to create a loop so that the program will scan and compare the numbers until the EOF, and I end up going into a loop that goes on forever. (I can get the code to scan and compare the first number. And if I copy that piece of code 30odd times it ‘will’ work, just not efficiently.
I have used that particular loop when displaying the entire contents of the file, but can’t seem to get it to work properly in this program.
I think the problem may be that "while ((c =getc(fp))!= 10);" keeps looping looking for line return and on the last line of file it might not be there. It might go directly to EOF which would hang the loop but im not too sure on how to fix it, or what the code is for fixing it, (im stil a beginner :-) )
Can anyone help me?