0

Hello All.

After couple hours reading posts here and all over the web, i wasnt able to find example of code to "rewrite it" my way.

All i need is:

1. read the file (txt),
2. scanf for string,
3. compare each line for this string,
4. if found printf this line.

I know how to load the file and print it. But just cannot found the way to compare string user will type (using scanf?) and then print only that line.

file *fd;
  char symbols; 
  fd = fopen("file.txt", "r");
  if (fd == NULL) {
    printf("Cannot open file");
  } else {
    while( !feof(fd) ) {
      fscanf(fd, "%c", &symbols);
      printf("%c", symbols);
    }
    
    fclose(fd);
    getch();
    return main();
  }

i read about tokens, strcn but as i am newbie (couple days) i dunno how to implement them. will keep searching but if some one could help, that would be nice. I pretty sure this is super easy for all of you..

2
Contributors
2
Replies
5
Views
5 Years
Discussion Span
Last Post by mochno
0

Ur code is 1 character at a time, u must take one line by line.
use stcmp to compare

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.