hqt

Space Delimeter - C

hqt
Jul 20th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(){
  5.     char s[100], d[100];
  6.     memset(d,0,sizeof(d));
  7.     char tokenizer[] = {" \t\f\n"};
  8.    
  9.     scanf("%[^\n]",s);
  10.     char * pch;
  11.     pch = strtok(s,tokenizer);
  12.     while (pch != NULL){
  13.         strncat(d,pch,strlen(pch));
  14.         strncat(d," ",1);
  15.         pch = strtok(NULL,tokenizer);
  16.     }
  17.     d[strlen(d)-1]='\0';
  18.     printf("Res:\n");
  19.     puts(d);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment