#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *file;
char ch, str[500], a=0;
char name[20], word[50], temp[50];
int i,lenght=0, b=0;
if((file=fopen("sample.txt" , "r"))==NULL)
{
printf("Error while opening file\n");
system("pause");
exit(1);
}
while (!feof(file))
{
fgets(str, 499, file);
printf("%s\n",str);
ch=fgetc(file);
if(ch!=' ')
{
a++;
word[b]=ch;
if(a > lenght)
lenght=a;f
for (i=1; i<=lenght; i++)
temp[i]= word[i];
}
}
printf("Longest word: ");
for (i=1; i<=lenght; i++)
{
printf("%c", temp[i]);
}
printf("\n");
fclose(file);
system("pause");
return 0;
}
Please someone help me with this,i need a C program which reads data from txt file and searchest the longest word in it,i have no more ideas on this,program seems to be working but have no output.