Advertisement
chunkyguy

sid

Dec 22nd, 2010
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. /*
  2.  author: sid
  3.  search arg 2 in arg 1
  4.  */
  5.  
  6. #include<stdio.h>
  7. #include<string.h>
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.     if(argc != 3)
  12.     {
  13.         printf("usage %s: <hay_string> <needle_string>\n",argv[0]);
  14.         return;
  15.     }
  16.    
  17.     char word[100];
  18.     int wc = 0;
  19.     int found = 0;
  20.     int i = 0;
  21.     for(; i < strlen(argv[1]); i++)
  22.     {
  23.         if(isspace(argv[1][i]))
  24.         {
  25.             word[wc] = '\0';
  26.             if(strstr(word,argv[2]))
  27.                 found++;
  28.             wc = 0;
  29.         }
  30.         word[wc++] = argv[1][i];
  31.     }
  32.    
  33.     printf("%s found %d times\n",argv[2],found);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement