Advertisement
MUstar

IoT C언어 0710 - EX12_3

Jul 15th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. //#include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char search(char *word, char *s_word);
  6.  
  7. int main(void)
  8. {
  9.     char word[100] , s_word[100];
  10.  
  11.     printf("문자 입력 : ");
  12.     fgets(word,sizeof(word),stdin);
  13.     while(1)
  14.     {
  15.         printf("검색할 문자열 입력 (종료는 end) : ");
  16.         fgets(s_word,sizeof(s_word),stdin);
  17.         s_word[strlen(s_word)-1] = '\0';
  18.         if(strcmp(s_word,"end")==0) break;
  19.         search(word,s_word);
  20.     }
  21.  
  22.     return 0;
  23. }
  24.  
  25. char search(char *word, char *s_word)
  26. {
  27.     char *temp, w_temp[100];
  28.     int cnt=0, s_cnt=0, size = strlen(s_word);
  29.  
  30.     strcpy(w_temp,word);
  31.     while(2)
  32.     {
  33.         if(strlen(w_temp+s_cnt)==1) break;
  34.         else
  35.         {
  36.             if(strncmp(w_temp+s_cnt,s_word,size) == 0)
  37.             {
  38.                 cnt++;
  39.                 s_cnt+=size;
  40.             }
  41.             else
  42.             {
  43.                 s_cnt++;
  44.             }
  45.         }
  46.     }
  47.     printf("검색결과 : %d\n",cnt);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement