← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/strcpy.c
diff options
context:
space:
mode:
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);
+ }
+}