Brain Fart .... help please.
How do I, in C, read a text file line by line and find a specific string within that line? The .txt file contains numbers, Symbols, Spaces, and Characters. I also need to be able to read spaces as spaces and not white spaces. I know this is a lot to ask of but, this shouldnt be that hard of a problem for me, but I've stumped myself. If anyone could help it would be much appreciated.
"There is humor in everything depending on which prespective you look from."
Edited by - chronoslade on September 30, 2001 11:49:20 AM
Anybody.......???
"There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
well..
{ Stating the obvious never helped any situation !! }
FILE *f = fopen("myfile.txt","r"); char mystring[80]; while(!feof(f)) { fgets(mystring,80,f); if(strstr(mystring,"abc")!=NULL) printf("found abc in string %",mystring); } fclose(f);
{ Stating the obvious never helped any situation !! }
Using "while(!feof(f))" while reading lines almost always reads the last line twice when you''re lacking the last endline. You should probably use:
Not a big issue, but it''s really annoying to have one line read twice and not know why .
[Resist Windows XP''s Invasive Production Activation Technology!]
for( ; ; ) { if(fgets(mystring,80,f) == NULL) break;}
Not a big issue, but it''s really annoying to have one line read twice and not know why .
[Resist Windows XP''s Invasive Production Activation Technology!]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement