I am trying to to read lines from a file
I want to print it using malloc, ....I don't know how long is the text in the file so I want then to increase storage by using realloc()
Code:#include <stdio.h> #include <string.h> int main (void) { FILE *fptr; char fileline; char line; fptr=fopen("c:\\c\\file.txt","r"); line=(char*)malloc(50); if(fptr!=0) { while (!feof(fptr)) { fgets(fileline+strlen(line),50,fptr); } } else { perror("\nError Opening File.\n"); } strcpy(line,fptr); puts(line); fclose(fptr); free(fileline); return 0; }



LinkBack URL
About LinkBacks


