Search file for string


/ Published in: C
Save to your folder(s)

usage:
srch(foo, bar.txt)


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.