c - Cannot print characters from a file -
i trying read file character character , print on screen. however, character not displaying, getting box 0001 in it. code
#include <stdio.h> #include <stdlib.h> int main() { file *fp; int ch; fp=fopen("myfile.txt", "rb"); while((ch = getc(fp)) !=eof){ putc(ch, stdout); } fclose(fp); return 1; }
you need check return values fopen, ensure opened file successfully, executing wrong directory. plus if file text file, should opening using "rt".
Comments
Post a Comment