summaryrefslogtreecommitdiff
path: root/src/c/copyfile/cf-ng.c
diff options
context:
space:
mode:
authorpankunull <panku_null@proton.me>2025-08-25 05:55:36 +0200
committerpankunull <panku_null@proton.me>2025-08-25 05:55:36 +0200
commita0e771c8b5f1e12d4bc3afeb8f40d17e76a4951a (patch)
tree866de5d286acb2de7bd0166c2332792135ffb21e /src/c/copyfile/cf-ng.c
parentbdb05a5943ce75a2ded5f4dbfa16d5e3de29093c (diff)
Added new stuff.
Diffstat (limited to 'src/c/copyfile/cf-ng.c')
-rw-r--r--src/c/copyfile/cf-ng.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/c/copyfile/cf-ng.c b/src/c/copyfile/cf-ng.c
new file mode 100644
index 0000000..8ff770a
--- /dev/null
+++ b/src/c/copyfile/cf-ng.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ int c;
+ size_t size = 1024; // initial buffer size
+ size_t len = 0;
+ char *buffer = malloc(size);
+ if (!buffer) {
+ perror("malloc");
+ return 1;
+ }
+
+ printf("Type input (Ctrl+D to end):\n");
+
+ while ((c = getchar()) != EOF) {
+ // Resize buffer if needed
+ if (len + 1 >= size) {
+ size *= 2;
+ char *tmp = realloc(buffer, size);
+ if (!tmp) {
+ free(buffer);
+ perror("realloc");
+ return 1;
+ }
+ buffer = tmp;
+ }
+
+ buffer[len++] = (char)c;
+ }
+
+ // Null-terminate string
+ buffer[len] = '\0';
+
+ printf("\nYou typed:\n%s\n", buffer);
+
+ free(buffer);
+ return 0;
+}