-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path17.c
More file actions
52 lines (42 loc) · 1.04 KB
/
Copy path17.c
File metadata and controls
52 lines (42 loc) · 1.04 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[100], word[20], mx[20], mn[20], c;
int i, j, flg;
printf("Input the string : ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0';
i = 0;
j = 0;
flg = 0;
for (i = 0; i < strlen(str); i++)
{
if (!isspace(str[i]) && isalnum(str[i]))
{
word[j++] = str[i];
}
else if (j != 0)
{
word[j] = '\0';
if (!flg)
{
flg = 1;
strcpy(mx, word);
strcpy(mn, word);
}
if (strlen(word) > strlen(mx))
{
strcpy(mx, word);
}
if (strlen(word) < strlen(mn))
{
strcpy(mn, word);
}
j = 0;
}
}
printf("The largest word is '%s' \nand the smallest word is '%s' \nin the string : '%s'.\n", mx, mn, str);
return 0;
}