Hi Guru,
I just need to ask help on how to create program that will determined the longest word using turbo C.
sample
Input: Follow the procedure
Output: follow, procedure
not quite sure what is wrong to my code
sample code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[50],longst[30],word[30];
int i,j=0,len;
clrscr();
printf("Enter the string\n");
gets(str);
len=strlen(str);
strcpy(longst," ");
for(i=0;i<=len;i++)
{
if(str[i]==' ' <str[i]=='\0')
{word[j]='\0';
if(strlen(word)>strlen(longst))
{
strcpy(longst,word);
}
j=0;
}else
{
word[j]=str[i];
j++;
}
}
printf("\n longest word is\t");
puts(longst);
getch();}