I can't slove this problem
my code print nothing
what's wrong with it ??
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define total 1000
int weight (char word[total])
{
int i;
int sum;
for (i=0;word[i]!='\0';i++)
{
sum+=i;
}
return sum;
}
char *getword (char temp[total])
{
static char max[total]={'\0'};
int lenth,maxlenth;
lenth=strlen(max);
maxlenth=strlen(temp);
if (lenth>=maxlenth)
{
if (lenth>maxlenth)
{
strcpy (max,temp);
}
if (lenth==maxlenth)
{
if(weight(temp)>weight(max))
strcpy (max,temp);
}
}
return max;
}
int main()
{
char c,word[total];
int i;
int offset=0;
int sum,sumword;
while ((c=getchar())!=EOF)
{
if (c==' ' ||c=='\t' ||c=='\n')
{
offset=0;
}
if (isalpha(c))
{
offset=1;
}
if(offset==1)
{
sum ++;
for(i=0;offset==0;i++)
{
word[i]=c;
sumword ++;
}
strcpy(word,getword(word));
}
}
float ave=(float)sum/sumword ;
printf("the longset word :%s\n",word);
printf("Average word length:%.2f\n",ave);
return 0;
}