c - Why am I getting a hyphen at start of file? -
i learning c , have tried build programme outputs own source. source:
#include <stdio.h> int s = 512; int main(){ file * fp; fp = fopen("hello.c","r"); char * line = (char *) malloc(s); int = 0; while (i == 0) { = feof(fp); printf("%s",line); fgets(line,s,fp); } fclose(fp); }
i have used tcc compiler , got output:
but notice, got hyphen before #include
. rest of output correct.
so please can explain why got hyphen??
you're printing first line before you've read anything.
#include <stdio.h> int main(){ file *fp = fopen("hello.c", "r"); char line[256]; while (fgets(line, sizeof line, fp) != null) printf("%s",line); fclose(fp); homecoming 0; }
c file-io
No comments:
Post a Comment