#include "stdio.h"
#include "stdlib.h"
int main()
{
FILE *fp;
int noOfLines =0;
char fname[]="Rtl_Prod_Id.txt";
printf(fname);
fp=fopen(fname,"r");
char ch;
do {
ch=fgetc(fp);
if (ch=='\n')
noOfLines++;
} while(ch!=EOF);
if (ch!='\n'&&noOfLines!=0)
noOfLines++;
fclose(fp);
printf("%d",noOfLines);
return 0;
}
I'm just trying to calculate the number of lines in my file. The same does not return me any result.
What are the possible mistakes that I make
Environment: AIX and compiler: CC
thank
Edit: my program compiles successfully, but nothing appears at runtime of the .Out file
PS: Although I got a response. thanks https://stackoverflow.com/users/434551/r-sahu . I changed char ch; on int ch; . but I wonder why? What's wrong with the char declaration ?, How am I going to check the "\ n" and EOF characters, why the whole afterwards?
source
share