C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
determine Longest word Posted by Michael Uchi on 18 Jan 2009 at 12:04 AM
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();}




Report
Re: determine Longest word Posted by MT2002 on 19 Jan 2009 at 6:20 PM
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.

Report
Re: determine Longest word Posted by smeezekitty on 20 Jan 2009 at 7:43 PM
a debugger may help
make sure it is seperating the words



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.