samir82show

grep a word function

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