Brain Fart .... help please.

Started by
3 comments, last by Chronoslade 22 years, 7 months ago
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
"There is humor in everything depending on which prespective you look from."
Advertisement
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..

     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:
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!]
You guys are wonderful thanks a lot!!!! Just one question... this will allow me to read in spaces as spaces? Unfortunatly this is a must......

"There is humor in everything depending on which prespective you look from."

Edited by - chronoslade on October 1, 2001 7:36:42 AM
"There is humor in everything depending on which prespective you look from."

This topic is closed to new replies.

Advertisement