Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading and writing files in C
#1
C provides functions for reading from and writing to files.

// Writing to a file
FILE *file = fopen("data.txt", "w");
if (file != NULL) {
    fprintf(file, "Hello, World!");
    fclose(file);
}

// Reading from a file
char buffer[100];
file = fopen("data.txt", "r");
if (file != NULL) {
    fgets(buffer, 100, file);
    printf("%s\n", buffer); // Output: Hello, World!
    fclose(file);
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Messages In This Thread
Reading and writing files in C - by Qomplainerz - 07-25-2023, 01:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing clean and maintainable code in C Qomplainerz 0 242 07-25-2023, 01:31 PM
Last Post: Qomplainerz
  Creating and using header files in C Qomplainerz 0 278 07-25-2023, 01:29 PM
Last Post: Qomplainerz
  Text and binary files in C Qomplainerz 0 253 07-25-2023, 01:24 PM
Last Post: Qomplainerz
  Writing your first "Hello, World!" program Qomplainerz 0 353 07-25-2023, 10:49 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 2 Guest(s)