Yes i made the changes as mentioned. But i was trying to get to the point what Elysia was referring to on how to figure out exact place where error occured.
Anyhow the modified code is as follows:
[insert]
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
FILE *fp;
int ch;
int nol= 0, not = 0, nob = 0, noc =0;
fp = fopen("C:\\Documents and Settings\\ROHAN\\Desktop\\DESKTOP\\filejava.txt", "r");
if(fp == NULL){
printf("\n Error opening the file");
return 0;
}
while(1){
ch = fgetc(fp);
if(ch == EOF)
break;
noc++;
if(ch == ' ')
nob++;
if(ch == '\n')
nol++;
if (ch == '\t')
not++;
}
fclose(fp);
printf("\n No of char = %d", noc);
printf("\n No of line = %d", nol);
printf("\n No of tab = %d", not);
printf("\n No of space = %d", nob);
return 0;
}
Its working perfectly fine.