From cba611a0c05859c316a9cfb7d7914b2281a26082 Mon Sep 17 00:00:00 2001 From: Pierre Kunzli <pierre.kuenzli@unige.ch> Date: Tue, 18 Oct 2022 19:43:37 +0200 Subject: [PATCH] ajout demo str --- Programmation/Code/Str/str.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Programmation/Code/Str/str.c diff --git a/Programmation/Code/Str/str.c b/Programmation/Code/Str/str.c new file mode 100644 index 0000000..c32653d --- /dev/null +++ b/Programmation/Code/Str/str.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <string.h> + +int main(int argc, char** argv){ + + // strlen example + printf("'%s' length : %zu\n", argv[1], strlen(argv[1])); + printf("'%s' length : %zu\n", argv[2], strlen(argv[2])); + + // strcpy example + int l1 = strlen(argv[1]); + char copy[l1+1]; + strcpy(copy, argv[1]); + + // strcmp example + if(strcmp(argv[1], copy) == 0){ + printf("'%s' == '%s'\n", argv[1], copy); + } else { + printf("'%s' != '%s'\n", argv[1], copy); + } + + if(strcmp(argv[1], argv[2]) == 0){ + printf("'%s' == '%s'\n", argv[1], argv[2]); + } else { + printf("'%s' != '%s'\n", argv[1], argv[2]); + } +} \ No newline at end of file -- GitLab