Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- char *my_token(char *ps);
- int main(void)
- {
- char str[80];
- char *p;
- printf("문장 입력 : ");
- fgets(str,sizeof(str),stdin);
- while((p = my_token(str)) != NULL)
- {
- printf("%s\n", p);
- }
- return 0;
- }
- char *my_token(char *ps)
- {
- char *end = 0;
- static char word[20];
- int i=0;
- for(int ec=0; ec<20; ec++)
- word[ec] = '\0';
- if(ps[0] == '\0') return NULL;
- while(1)
- {
- if(ps[i] == ' ')
- {
- i++;
- break;
- }
- if(ps[i] =='\0')
- {
- word[i-1]=0;
- break;
- }
- word[i] = ps[i];
- i++;
- }
- stpcpy(ps,ps+i);
- return word;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement