11-file.c 275 B

1234567891011121314
  1. #include <stdio.h>
  2. int main() {
  3. FILE *file = fopen("file.txt", "w");
  4. if (file != NULL) {
  5. fprintf(file, "This is some text.");
  6. fclose(file);
  7. printf("File created and written successfully.\n");
  8. } else {
  9. printf("Error opening file.\n");
  10. }
  11. return 0;
  12. }