Posted By

bcnjr5 on 01/25/13


Tagged


Versions (?)

Search file for string


 / Published in: C
 

usage: srch(foo, bar.txt)

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char srch(char *string_to_find, char *filename)
  6. {
  7. FILE *fp=fopen("M", "r");
  8. char tmp[256]={0x0};
  9. while(fp!=NULL && fgets(tmp, sizeof(tmp),fp)!=NULL)
  10. {
  11. if (strstr(tmp, string_to_find))
  12. printf("%s", tmp);
  13. }
  14. if(fp!=NULL) fclose(fp);
  15. return tmp;
  16. }

Report this snippet  

You need to login to post a comment.