Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1) в заданном тексте найти самую длинную фразу и самое длинное слово.
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- int main(){
- printf("Input text: \n");
- char longest_word[50] = {};
- char longest_phrase[255] = {};
- char buf_word[50];
- char buf_phrase[255];
- char c;
- int index_word = 0;
- int index_phrase = 0;
- do{
- c = getche();
- if(c != ' ')
- buf_word[index_word++] = c;
- else{
- buf_word[index_word] = 0;
- if(strlen(longest_word) < strlen(buf_word))
- strcpy(longest_word, buf_word);
- index_word = 0;
- }
- if(c != '.')
- buf_phrase[index_phrase++] = c;
- else{
- buf_phrase[index_phrase] = 0;
- if(strlen(longest_phrase) < strlen(buf_phrase))
- strcpy(longest_phrase, buf_phrase);
- index_phrase = 0;
- }
- }while(c != 13);
- printf("\nlongest word: %s\n", longest_word);
- printf("longest phrase: %s\n", longest_phrase);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement