Kimossab

Looking word Do in a file

May 11th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void DoAction()
  5. {
  6.     printf("1 ");
  7. }
  8.  
  9. void main()
  10. {
  11.     FILE *fi = fopen("blablabla.txt", "r");
  12.     if(fi == NULL)
  13.         return;
  14.     char String[200];
  15.     char *S;
  16.  
  17.     while(!feof(fi))
  18.     {
  19.         fgets(String, sizeof(String), fi);
  20.         /*for(int i=0; i < sizeof(String); i++)
  21.         {
  22.             if(String[i] == 'd' && String[i+1] == 'o' && String[i+2] == ' ')
  23.                 DoAction();
  24.         }*/
  25.         S=strstr(String, "do ");
  26.         while(S != NULL)
  27.         {
  28.             DoAction();
  29.             S=strstr(S+3, "do "); // 3 é o tamanho da palavra do mais o espaço strstr procura a string "do " dentro da string S
  30.         }
  31.     }
  32.     fclose(fi);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment