← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/strcpy.c
diff options
context:
space:
mode:
authorDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
committerDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
commitb3e9e62599532050fc776c5e8f076915b56c2235 (patch)
treeaf252346106a61b18cc6fc6fdbd32e962d096f1c /strcpy.c
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice
Diffstat (limited to 'strcpy.c')
-rw-r--r--strcpy.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/strcpy.c b/strcpy.c
new file mode 100644
index 0000000..a34dd71
--- /dev/null
+++ b/strcpy.c
@@ -0,0 +1,17 @@
+#include <string.h>
+#include <stdio.h>
+int main(int argc, char* argv[argc+1]) {
+ size_t const len = strlen(argv[0]); // Computes the length
+ // Initialized VLA, /*@\C{23}*/
+ // terminates array with 0 character
+ char name[len+1] = { };
+ // Copies the program name
+ memcpy(name, argv[0], len);
+ if (!strcmp(name, argv[0])) {
+ printf("program name \"%s\" successfully copied\n",
+ name);
+ } else {
+ printf("copying %s leads to different string %s\n",
+ argv[0], name);
+ }
+}