-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortLongWord.c
38 lines (33 loc) · 919 Bytes
/
shortLongWord.c
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
33
34
35
36
37
38
// !Have to take user input
#include <stdio.h>
#include <string.h>
#define MAX 5
int shortestWord(char **string);
int longestWord(char **string);
int main(void)
{
char *str[MAX] = {"Hello,", "my", "name", "is", "Tuhin Dhar"};
printf("The length of the shortest word is %d\n", shortestWord(str));
printf("The length of the longest word is %d\n", longestWord(str));
return 0;
}
int shortestWord(char **string)
{
int count, shortest = strlen(string[0]);
for (int i = 0, n = MAX; i < n; i++)
{
count = strlen(string[i]);
shortest = count < shortest ? count : shortest;
}
return shortest;
}
int longestWord(char **string)
{
int count, longest = strlen(string[0]);
for (int i = 0, n = MAX; i < n; i++)
{
count = strlen(string[i]);
longest = count > longest ? count : longest;
}
return longest;
}