Count the words of each line in a file. No suppositions will
be made regarding the maximum length of a line. And my not working c code:

//Count the words of each line in a file. No suppositions will
//be made regarding the maximum length of a line.
#include<stdio.h>
#include<string.h>


int main()
{
FILE *fisi,*fis;
int k,i,line = 1;
char *pch;
char *s;
if ((fisi = fopen ("fis.txt","r")) != NULL)
{
fis = fopen("fis.txt","r");
i = getc(fisi);
while (i != EOF)
{
while (i != 10)
{
line++;
i = getc(fisi);
}
if(fgets(s,line,fis))
{
k = 0;
pch = strtok (s," ");
while (pch != NULL)
{
k++;
pch = strtok (NULL, " ");
}
printf ("%d \n",k);
}
line = 1;
i = getc(fisi);
}
if ((fclose (fisi) == EOF) && (fclose(fis) == EOF))
printf ("Some errors occured in the process of closing the file!");
}
else
printf ("There were some problems with the input data file!");
return 0;
}


I must do it in c not c++!

So why post it on the C++ forum then?
Also, when are you going to figure out code tags.

>> Warp your codes in coding tags
>> It is c++ forum not a c forum
>> i has a datatype int , it should be char
>>Use ascii codes when you use char

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.