Advertisement
Lisaveta777

Almost done

Dec 5th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. #define SIZE 80
  5.  
  6.  
  7. //Ввести предложение длиной не более 80 символов.
  8. //Вывести слова, которые начинаются на ту же букву,
  9. // что и последнее слово, и
  10. //их количество. Количество пробелов между словами произвольно.
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16.     char target_c,ch_arr[SIZE]="nata katja klen lena kal";
  17.     int i,target_i,count,in_word,arr[SIZE]={0};
  18.     in_word  = count = 0;
  19.     for(i=0;i<SIZE;i++)//first symbol of last word
  20.     {
  21.         if( isalpha(ch_arr[i])  &&in_word==0)//first symbol in word
  22.         {
  23.             in_word=1;
  24.             target_c = ch_arr[i];
  25.             target_i = i;
  26.             arr[i]=1;//start of word in int array
  27.         }
  28.  
  29.         if( !isalpha(ch_arr[i]) && in_word)//out of word
  30.         {
  31.             in_word = 0;
  32.             arr[i]= -1;//end of word
  33.  
  34.         }
  35.     }//end of for
  36.  
  37.  
  38.     for(i=0;i<SIZE;i++)
  39.     {
  40.         printf("%c",ch_arr[i]);
  41.     }
  42.     printf("\n");
  43.     for(i=0;i<SIZE;i++)
  44.     {
  45.         printf("%d",arr[i]);
  46.     }
  47.     printf("\n");
  48.  
  49.  
  50.     for(i=0;i<SIZE;i++)//print and count words
  51.     {
  52.         if( arr[i]==1 &&ch_arr[i]==target_c)
  53.             //first symbol in word equals target
  54.         {
  55.             count++;
  56.             while(arr[i]!=-1)
  57.             {
  58.                printf("%c",ch_arr[i]);
  59.                i++;
  60.             }
  61.         }
  62.  
  63.     }//end of for
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement