This commit is contained in:
Christoph J. Scherr 2023-10-30 10:56:10 +01:00
parent 5532922411
commit b129125780
1 changed files with 22 additions and 1 deletions

View File

@ -9,12 +9,33 @@ int my_strlen(const char *s) {
return len;
}
void my_strcpy(char *dest, const char *src) {
register int i = 0;
while (src[i]) {
dest[i] = src[i];
i++;
}
// one last time
dest[i] = src[i];
}
int main() {
char word[] = "hallo\0"; // not NULL terminated
char my_buf[6];
char std_buf[6];
printf("strlen\n");
printf("word is %d long\n", my_strlen(word));
printf("word is actually %lu long\n", strlen(word));
printf("success: %b", my_strlen(word) == strlen(word));
printf("success: %b\n", my_strlen(word) == strlen(word));
printf("\nstrcpy\n");
my_strcpy(my_buf, word);
strcpy(std_buf, word);
printf("word: \"%s\"\n", word);
printf("my_buf: \"%s\"\n", my_buf);
printf("std_buf: \"%s\"\n", std_buf);
printf("success: %b\n", 0 == strcmp(my_buf, std_buf));
return 0;
}