I want to get the occurence of the symbol ';' for each line of this C program. I type the name of the file Source.c and try to count the occuring symbol, but i am getting the value for ALL of the ';' for each line.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>/* For exit() function */
int main()
char file_name[150];
FILE *file2 = 0;
gets(file_name);
{
int rows = 1;//broq na vsichki redove
int dotcoma[150];
int j;
int c=0;
file2 = fopen(file_name, "r");//otvarq faial za chetene
if (file2 == NULL){
printf("Cannot open %s\n", file_name);
exit(2);
}//if
for (j = 0; j < 150; j++)
dotcoma[j]=0;
do{
c = fgetc(file2);
if (c == '\n') rows++;
if (';' == c)
dotcoma[rows-1] ++;
} while (c != EOF);//chete do kraq na faila
if (ferror(file2)){
printf("Error reading file.\n");
}//if
printf("The number of the symbols on a row ");
printf("Row %d: %f\n", j + 1, (float)dotcoma[j]);
}
if (fclose(file2) == EOF){
printf("Cannot close %s\n", file_name);
}
_getche();
return 0;
}