samir82show

boolean type grep

Feb 24th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAX 100
  4. unsigned char
  5. read_line(char *line, char *word);
  6. int main()
  7. {
  8. char line[MAX];
  9. if (read_line(line, "test_word") != 0)
  10. printf("found word\n");
  11. else
  12. printf("not found\n");
  13. return (0);
  14. }
  15. unsigned char
  16. read_line(char *line, char *word) {
  17. int c;
  18. unsigned char i = 0;
  19. while ((c = getchar()) != EOF && i < MAX - 1)
  20. line[i++] = c;
  21. line[i] = '\0';
  22. if (strstr(line, word) != 0)
  23. return (1);
  24. else
  25. return (0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment