![]() ![]() | io/simple-write.c - Skrivning af tegn fra en tekststreng på en tekstfil. | Lektion 13 - slide 9 : 32 Program 1 |
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *output_file_pointer; char *str = "0123456789abcdefghijklmnopqrstuvw"; output_file_pointer = fopen("first-file", "w"); if (output_file_pointer != NULL){ /* File could be opened */ while (*str != '\0'){ fputc(*str, output_file_pointer); str++; } fclose(output_file_pointer); } else{ printf("Could not open output file. Bye."); exit(EXIT_FAILURE); } return 0; }