-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy patharrayCountLongestWord.c
More file actions
32 lines (26 loc) · 911 Bytes
/
Copy patharrayCountLongestWord.c
File metadata and controls
32 lines (26 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
/*
Your job is to find the length of the longest word in a text with no punctuation
or special characters of any kind - only contains words. To do so, write a C-program
that takes as a input first the number of words in a text, followed by all of the words
in the text. The output of your program should be the length of the longest word in the text.
To simplify your program, you can assume that the longest word will not exceed 100 characters.
*/
int main(void) {
int i, length, numWords, maxNum=0, cnt;
char word[101];
printf("Enter number of words: ");
scanf("%d", &numWords);
for (i=0; i<numWords; i++) {
printf("Enter word: n");
scanf("%s", word);
cnt = 0;
while (word[cnt] != '\0'){
cnt++;
}
if (cnt > maxNum) {
maxNum = cnt;
}
}
printf("%d\n", cnt);
}