Chapter:

Strings-in-C-programming-

Write a program in C to find largest and smallest word in a string.

#include <stdio.h>
#include <string.h>
#include <ctype.h>

void main()
{
    char str[100], word[20], mx[20], mn[20], c;
    int i = 0, j = 0, flg = 0;
	
       printf("\n\nFind the largest and  smallest word in a string :\n");
       		
 
	printf("Input the string : ");
    i = 0;
    do
    {
        fflush(stdin);
        c = getchar();
        str[i++] = c;
 
    } while (c != '\n');
    str[i - 1] = '\0';
    for (i = 0; i < strlen(str); i++)
    {
        while (i < strlen(str) && !isspace(str[i]) && isalnum(str[i]))
        {
            word[j++] = str[i++];
        }
        if (j != 0)
        {
            word[j] = '\0';
            if (!flg)
            {
                flg = !flg;
                strcpy(mx, word);
                strcpy(mn, word);
            }
            if (strlen(word) > strlen(mx))
            {
                strcpy(mx, word);
            }
            if (str....
Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-