vasylmartyniv

C2S1-Yulia-2

Oct 1st, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void deleteword(char str[],int num){
  5.     char s[255];
  6.     int count=1;
  7.  
  8.     s[0]='\0';
  9.     char *token = strtok (str, " ");
  10.     while  (token  !=NULL)
  11.     {  
  12.         if (count != num)    { strcat (s,token); strcat (s," "); }
  13.         token = strtok(NULL," ");
  14.         ++count;
  15.     }
  16.  
  17.     strcpy(str,s);
  18. }
  19.  
  20. int main(){
  21.     char str[255];
  22.     printf("Type string: ");
  23.     gets(str);
  24.     int n;
  25.     while(true){
  26.         printf("\nType word number(0 to exit): ");
  27.         scanf("%d",&n);
  28.         if(n==0){
  29.             break;
  30.         }
  31.         deleteword(str,n);
  32.         for(int i=0;i<strlen(str);i++){
  33.             printf("%c",str[i]);
  34.         }
  35.     }
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment