MUstar

IoT C언어 0710 - EX13_3

Jul 15th, 2017
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char *my_token(char *ps);
  5.  
  6. int main(void)
  7. {
  8.     char str[80];
  9.     char *p;
  10.  
  11.     printf("문장 입력 : ");
  12.     fgets(str,sizeof(str),stdin);
  13.     while((p = my_token(str)) != NULL)
  14.     {
  15.         printf("%s\n", p);
  16.     }
  17.    
  18.     return 0;
  19. }
  20.  
  21. char *my_token(char *ps)
  22. {
  23.     char *end = 0;
  24.     static char word[20];
  25.     int i=0;
  26.    
  27.     for(int ec=0; ec<20; ec++)
  28.         word[ec] = '\0';
  29.     if(ps[0] == '\0') return NULL;
  30.     while(1)
  31.     {
  32.         if(ps[i] == ' ')
  33.         {
  34.             i++;
  35.             break;
  36.         }
  37.         if(ps[i] =='\0')
  38.         {
  39.             word[i-1]=0;
  40.             break;
  41.         }
  42.         word[i] = ps[i];
  43.         i++;
  44.     }
  45.     stpcpy(ps,ps+i);
  46.     return word;
  47. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×