I want to read from file line by line without using fgets. I have the following code but in the end crashes and i can not find the what is the problem
Code:# include <stdio.h> # include <stdlib.h> int main(){ char buf[60]; int i=0; char ch; FILE *f; f=fopen("c.txt","r"); if ( f== NULL ){ printf("ERROR OPENING THE FILE"); return(1); } while (!feof(f)) { do{ ch=fgetc(f); buf[i]=ch; i++; }while(ch!='\n'); buf[i-1]='\0'; i=0; printf("%s\n",buf); } fclose(f); }