| simple-read.c - Læsning af tegn fra en tekstfil til en tekststreng. | Lektion 10 - slide 9 : 28 Program 2 |
#include <stdio.h>
#define MAX_STR_LEN 100
int main(void) {
FILE *input_file_pointer;
char str[MAX_STR_LEN];
int ch;
int i = 0;
input_file_pointer = fopen("first-file", "r");
while ((ch = fgetc(input_file_pointer)) != EOF){
str[i] = ch;
i++;
}
str[i] = '\0';
printf("Read from file: %s\n", str);
fclose(input_file_pointer);
return 0;
}