+ 3
I am trying to count the number of lines of files with this function but things finish with an ifinite loop !!
#include<stdio.h> #include<stdlib.h> long count(char * fileName ) { long compteur = 0 ; char caracter ; fich = fopen( fileName,"r") ; if ( fich != NULL ) { do { caracter = fgetc(fich) ; if ( caracter = '\n' ) compteur++ ; }while ( caractere != EOF ) ; } fclose(fich) ; return compteur ; } ;
5 Respostas
+ 3
I found it !! 😃 it's a stupid fault , in the condition of "if" I had to use "==" not "=" !! thanks for trying help 😊
+ 2
the main function is simple :
( "dictionnary.txt" is a file that contain 8 words, each word in a line)
int main()
{
printf(" the number of words is : %ld", count("dictionnary.txt") );
return 0 ;
}
+ 2
I am working on windows, the eol is '\n'
+ 1
where is your main() function?
Also if the file was created in Windows, I think the eol chatacter is '\r'
+ 1
I also overlooked it :)