notes/sandbox/open2.c
2023-04-22 00:41:54 -07:00

24 lines
388 B
C

#include <stdio.h>
#include <stdlib.h>
int main() {
FILE * fptr;
char c;
// Open file
fptr = fopen("file.txt", "r");
if (fptr == NULL) {
printf("Cannot open file \n");
exit(0);
}
// Read contents form file
c = fgetc(fptr);
while (c != EOF) {
printf("%c", c);
c = fgetc(fptr);
}
fclose(fptr);
return 0;
}