From 17abac161eebbc193900e3466f5bc60945e4e532 Mon Sep 17 00:00:00 2001 From: Robert Preston Date: Tue, 30 Jun 2026 09:04:35 +1000 Subject: [PATCH] copy C clone complete? --- c_programming/files/copy.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/c_programming/files/copy.c b/c_programming/files/copy.c index 12a31e9..2575826 100644 --- a/c_programming/files/copy.c +++ b/c_programming/files/copy.c @@ -1,2 +1,32 @@ +#include -FILE *input = fopen("in.txt", "r"); \ No newline at end of file +int main(void) +{ + FILE *input = fopen("in.txt", "r"); + if (input == NULL) + { + perror("Failed to open in.txt"); + return 1; + } + FILE *output = fopen("out.txt", "w"); + if (output == NULL) + { + perror("Failed to open out.txt") + fclose(input); + return 1; + } + char c; + while (fread(&c, sizeof(char), 1, input) != 0) + { + fwrite(&c, sizeof(char), 1, output); + } +} + +/* +TODO: ++ clone: clone git repository and start working on copy.c +- first: go through part 3 of cs50 week 4 memory section.pdf +- make: get copy.c compiling with make +- complete: fix all problems and ensure the demo program works as intended +- wait: if I need to go work on another file, it will go in a wait: task. +*/