Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define SIZE 80
- //Ввести предложение длиной не более 80 символов.
- //Вывести слова, которые начинаются на ту же букву,
- // что и последнее слово, и
- //их количество. Количество пробелов между словами произвольно.
- int main()
- {
- char target_c,ch_arr[SIZE]="nata katja klen lena kal";
- int i,target_i,count,in_word,arr[SIZE]={0};
- in_word = count = 0;
- for(i=0;i<SIZE;i++)//first symbol of last word
- {
- if( isalpha(ch_arr[i]) &&in_word==0)//first symbol in word
- {
- in_word=1;
- target_c = ch_arr[i];
- target_i = i;
- arr[i]=1;//start of word in int array
- }
- if( !isalpha(ch_arr[i]) && in_word)//out of word
- {
- in_word = 0;
- arr[i]= -1;//end of word
- }
- }//end of for
- for(i=0;i<SIZE;i++)
- {
- printf("%c",ch_arr[i]);
- }
- printf("\n");
- for(i=0;i<SIZE;i++)
- {
- printf("%d",arr[i]);
- }
- printf("\n");
- for(i=0;i<SIZE;i++)//print and count words
- {
- if( arr[i]==1 &&ch_arr[i]==target_c)
- //first symbol in word equals target
- {
- count++;
- while(arr[i]!=-1)
- {
- printf("%c",ch_arr[i]);
- i++;
- }
- }
- }//end of for
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement