#include <stdio.h>
#include <string.h>
int main() {
char src[40], dest[12];
memset(dest, '\0', sizeof(dest));
strcpy(src, "hello how are you");
strncpy(dest, src, 10); //9 for string, 1 for the \0
printf("show src: %s(length: %ld)\n", src, strlen(src)); //size_t = ld/long unsigned int
printf("show dest: %s(length: %ld)\n", dest, strlen(dest));
//strcat
char string1[] = " my friend";
char input[80];
printf("enter a message to be concatenated: ");
scanf("%s", input);
printf("%s\n", strncat(input, string1, 5));
//strcmp
printf("strcmp(\"A\", \"A\") is %d\n", strcmp("A", "A"));
printf("strcmp(\"A\", \"B\") is %d\n", strcmp("A", "B"));
printf("strcmp(\"apple\", \"Apple\") is %d\n", strcmp("apple", "Apple"));
printf("strcmp(\"Apple\", \"apple\") is %d\n", strcmp("Apple", "apple"));
printf("strcmp(\"apple\", \"apple\") is %d\n", strcmp("apple", "apple"));
if(strncmp("Jieun", "Jie", 3) == 0)
{
printf("3 chars of \"Jieun\" and \"Jie\" is same\n");
}
if(strncmp("Jie", "Jieun", 3) == 0)
{
printf("3 chars of \"Jie\" and \"Jieun\" is same\n");
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: