From 4e74ed99017fc63ac19722caf2c7ec899b2ca8f6 Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 3 Feb 2016 11:41:14 +0100 Subject: [PATCH] 5.4 --- C-RK/C-RK-Week1/main.c | 56 ++++++++++++++++++++++++++++++++++++++++-- C-RK/C-RK-Week1/main.h | 3 ++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/C-RK/C-RK-Week1/main.c b/C-RK/C-RK-Week1/main.c index b505468..9dbe11e 100644 --- a/C-RK/C-RK-Week1/main.c +++ b/C-RK/C-RK-Week1/main.c @@ -4,7 +4,7 @@ void main() { - char string[100]; + /*char string[100]; int result = strcpy(string, "test"); printf("result %d, string %s\n", result, string); @@ -16,7 +16,35 @@ void main() strCat(&s1, &s2); - printf("Nieuw string: %s\n", s1); + printf("Nieuw string: %s\n", s1);*/ + + //gaat goed + char s1[10]; + strcpy(s1, "taart"); + + char s2[10]; + strcpy(s2, "art"); + + printf("Result taart en art: %d\n", strend(s1, s2)); + + //gaat niet goed, niet hetzelfde + char s3[10]; + strcpy(s3, "taart"); + + char s4[10]; + strcpy(s4, "taa"); + + printf("Result taart en taa: %d\n", strend(s3, s4)); + + //gaat niet goed, niet s6 > s5 + char s5[10]; + strcpy(s5, "taart"); + + char s6[20]; + strcpy(s6, "verjaardagstaart"); + + printf("Result taart en verjaardagstaart: %d\n", strend(s5, s6)); + } void strCat(char* a, char* b) @@ -29,4 +57,28 @@ void strCat(char* a, char* b) i++; while((a[i++] = b[j++]) != '\0') ; +} + +int strend(char s[], char t[]) +{ + int sls,slt; + + sls = strlen(s); + slt = strlen(t); + + if (slt > sls) { + return 0; + } + + sls--; + + for (int i = slt - 1; i >= 0; i--) + { + if (t[i] != s[sls]) { + return 0; + } + sls--; + } + + return 1; } \ No newline at end of file diff --git a/C-RK/C-RK-Week1/main.h b/C-RK/C-RK-Week1/main.h index 29286aa..1e22255 100644 --- a/C-RK/C-RK-Week1/main.h +++ b/C-RK/C-RK-Week1/main.h @@ -1,2 +1,3 @@ #pragma once -void strCat(char* a, char* b); \ No newline at end of file +void strCat(char* a, char* b); +int strend(char s[],char t[]); \ No newline at end of file