From 8802b4fa27ce58686027e92e9b32a3952e99afb6 Mon Sep 17 00:00:00 2001 From: "ry.yamafuji" Date: Sun, 7 Dec 2025 19:11:11 +0900 Subject: [PATCH] =?UTF-8?q?C=E8=A8=80=E8=AA=9E=E7=92=B0=E5=A2=83=E6=A7=8B?= =?UTF-8?q?=E7=AF=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- readme/c.md | 5 ++++- src/c/cp.c | 34 ++++++++++++++++++++++++++++++++++ src/{ => c}/hello.c | 0 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/c/cp.c rename src/{ => c}/hello.c (100%) diff --git a/Makefile b/Makefile index d148c63..af06e3f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -Wall -Wextra -O2 TARGET = dist/hello -SRC = src/hello.c +SRC = src/c/hello.c $(TARGET): $(SRC) $(CC) $(CFLAGS) $(SRC) -o $(TARGET) diff --git a/readme/c.md b/readme/c.md index e560080..33c739b 100644 --- a/readme/c.md +++ b/readme/c.md @@ -1 +1,4 @@ -# C言語について \ No newline at end of file +# C / C++言語について + +* コンパイラ: GCC / G++ +* ビルド管理: Makefile \ No newline at end of file diff --git a/src/c/cp.c b/src/c/cp.c new file mode 100644 index 0000000..d00f136 --- /dev/null +++ b/src/c/cp.c @@ -0,0 +1,34 @@ +#include + +int main(int argc, char *argv[]) { + + // 引数のチェック 3以外ならエラー + if (argc != 3) { + fprintf(stderr, "Usage: %s src dest\n", argv[0]); + return 1; + } + + // ファイルのオープン + FILE *src = fopen(argv[1], "rb"); + FILE *dst = fopen(argv[2], "wb"); + + // オープン失敗時のエラーチェック + if (!src || !dst) { + perror("File open error"); + return 1; + } + + // ファイルのコピー 4096バイトずつ書き込む + char buf[4096]; + size_t n; + + // 読み込みと書き込みのループ + while ((n = fread(buf, 1, sizeof(buf), src)) > 0) { + fwrite(buf, 1, n, dst); + } + + fclose(src); + fclose(dst); + + return 0; +} diff --git a/src/hello.c b/src/c/hello.c similarity index 100% rename from src/hello.c rename to src/c/hello.c