#include <stdio.h>
#include <stdlib.h>
int main(void)
{
const char* fname = "d:/info.txt";
int status = EXIT_FAILURE;
FILE* fp = fopen(fname, "w+");
if (!fp) {
perror("File opening failed");
return status;
}
fputs("text to write to file\n", fp);
rewind(fp);
int ch;
while ((ch = fgetc(fp)) != EOF) {
putchar(ch);
}
if (ferror(fp)) {
puts("Error reading file");
}
else if (feof(fp)) {
puts("End of file - success");
status = EXIT_SUCCESS;
}
fclose(fp);
remove(fname);
return status;
}
/*
run:
text to write to file
End of file - success
*/