Code
WAP in C to find the largest word in a sentence?
Question From IOE 2075 Regular Ashwin. I found this too hard yet satisfying!
Rate
#include
#include
int main(){
char getString[200], present_str[200];
static char greatest[200];
int i = 0, j = 0;
printf("Enter any sentence:\n");
gets(getString);
while (1)
{
if ((getString[i]== ' ') || (getString[i]== '\0'))
{
present_str[j] = '\0';
if (strlen(greatest)<strlen(present_str))
{
strcpy(greatest, present_str);
}
if (getString[i]=='\0')
{
break;
}
j = 0;
i++;
continue;
}
present_str[j]=getString[i];
j++;
i++;
}
printf("The largest word is '%s'", greatest);
return 0;
}
Add comment:
Total 0 comments