#include #include #include int main(void) { FILE *fp; size_t count; const char *str = "hello\n"; fp = fopen("sample.txt", "w"); if(fp == NULL) { perror("failed to open sample.txt"); return EXIT_FAILURE; } count = fwrite(str, strlen(str), 1, fp); printf("Wrote %u bytes. fclose(fp) %s.\n", count, fclose(fp) == 0 ? "succeeded" : "failed"); return EXIT_SUCCESS; }