I need to find the number of lines in file which started with spaces. The following is the idea I had but it doesn't seem to work:
void SearchSymbolInLine(FILE *fp);
int main()
{
FILE * pFile;
char arr[80]={0};
char c[80]={0};
fflush(stdin);
printf("Enter the file name:\n");
gets(c);
if(!(fp=fopen(fileName, "rt")))
{
printf("The file was not found\n");
}
else
{
SearchSymbolInLine(fp);
}
return 0;
}
void SearchSymbolInLine(FILE *fp)
{
char line[100];
int ch=0;
int countA=0;
while ((fgets(line,99,fp))!=NULL)
{
if(line[0]==' ')
{
countA++;
}
}
printf("a= %d\n", countA);
}
Please help. I do not know whether it should be read line by line to obtain. As far as I can tell I think the problem is that I can't limited review in the first character of the line.And I can't distinguish lines. I guess it would work with reading line by line but it is really complex. I think that there is a simpler way.