determine Longest word

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
#include
#include


void main()

{

char str[50],longst[30],word[30];

int i,j=0,len;

clrscr();

printf("Enter the string
");

gets(str);

len=strlen(str);

strcpy(longst," ");

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

{

if(str[i]==' ' <str[i]=='')

{word[j]='';

if(strlen(word)>strlen(longst))

{

strcpy(longst,word);

}

j=0;
}else

{

word[j]=str[i];

j++;

}

}

printf("
longest word is ");

puts(longst);

getch();}




Comments

  • Why do they still have instructors using Turbo C? Alot of the code in your program is very non standard (void main, for example).

    Anyways, do you get any errors? What is wrong with it? Is it doing something that is not expected? If so, what is it? Posting what the problem is makes it easier for others to find a solution.

    Finally, please use the code tags when posting code--it makes your code easier to read.

  • a debugger may help
    make sure it is seperating the words
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories