hi
i want to write my own fgets code.
any help make me happy.Thanks.Code:#include <stdio.h> #include <ctype.h> #include <stdlib.h> //***********MY FGETS FUNCTION************** char *Tomgets(FILE *filex/*,int length_of_array*/) { char *p; char c; int i=0; int len=-1; //abc\0 0 1 2 3 for(i=0;i<100;i++)//in here my problem:i dont know how to stop my loop,i dont want to //use eof feof etc. //What is the end of file character? '\0' no i tried but didnt worked.if i find the end of //file,i can //define my size of pointer,so it is important. //For example if the end of file char='\000' i can write this c!='\000' instead of 100 it //would work. { c=(fgetc(filex)); printf("%c",c); len++; } p=calloc(len,sizeof(char)); for(i=0;i<len;i++) p[i]=c; p[i]='\0'; return p; //printf("%s",p); } //**************************************** int main(void) { int i=0; FILE *fp; char *content; if((fp=fopen("t.txt", "r")) == NULL) { perror("Error: unable to open the input file"); return 0; } //content=calloc(1000,sizeof(char)); //fgets(content,1000,fp); content=Tomgets(fp);//if i do this, i dont have to do the memory allocation of content. printf("%s",content); printf("\n\n"); fclose(fp); return 0; }