Headlines
Loading...
C Program to read a set of lines from stdin and print the longest line.

C Program to read a set of lines from stdin and print the longest line.

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

            char s[20][80];

            int i,j,k,l,n,max=0;

            clrscr();

            printf("How Many Lines You Want To Enter==");

            scanf("%d",&n);

            printf("\nEnter %d Lines,Lines Will End After Pressing Only Enter\n",n);

            flushall();

            for(i=0;i<n;i++)

                        gets(s[i]);

            j=0;

            for(i=0;i<n;i++)

            {

                        l=strlen(s[i]);

                        if(l>max)

                        {

                                    max=l;

                                    j=i;

                        }

            }

            printf("\nLongest String Is \n");

            printf("\n%s",s[j]);

getch();

}

 

/*Output

How Many Lines You Want To Enter==3

 

Enter 3 Lines,Lines Will End After Pressing Only Enter

abc xyz

abc college of management studies

master of business applications

 

Longest String Is

 

abc college of management studies

*/

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***