0

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++!

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Majestics
0

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

Edited by happygeek: fixed formatting

0

>> 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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.