![]() ![]() ![]() | simple-read-update.c - Læsning og skrivning af fil med r+ (kun på Unix). | Lektion 10 - slide 11 : 28 Program 2 |
#include <stdio.h> #define MAX_STR_LEN 100 int main(void) { FILE *input_file_pointer; char str[MAX_STR_LEN], ch; int i = 0; input_file_pointer = fopen("first-file", "r+"); while ((ch = fgetc(input_file_pointer)) != EOF){ str[i] = ch; fflush(input_file_pointer); fputc('X', input_file_pointer); fflush(input_file_pointer); i++; } str[i] = '\0'; printf("Read from file: %s\n", str); fclose(input_file_pointer); return 0; }