c_base实现MyStrpy函数 Mystrcat函数Mystrcmp函数

#include 
char *MyStrcpy(char *dest, const char* src)
{
	char *temp = dest;
	while(*src != '\0')
	{
		*dest = *src;
		dest++;
		src++;
	}
	*dest = '\0';
	return temp;
}

int main(int argc, const char *argv[])
{

	char arr[] = "hello word ";
	char arr2[32];
	MyStrcpy(arr2,arr);
	printf("%s\n",arr2);
	return 0;
}
#include 

char* myStrcat(char* dest, const char* src) 
{
	char* temp = dest;  
	while (*dest != '\0')
	{
		dest++;
	}

	while (*src != '\0') {
		*dest = *src;
		dest++;
		src++;
	}
	*dest = '\0';  
	return temp;
}

int main() 
{
	char destination[20] = "Hello, ";
	char source[] = "world!";

	myStrcat(destination, source);
	printf("%s\n",destination);
	return 0;
}
#include 

int myStrcmp(const char* str1, const char* str2) 
{
    while (*str1 != '\0' && *str1 == *str2) 
	{
        str1++;
        str2++;
    }

    return *str1 - *str2;
}

int main() {
    const char* str1 = "Hello";
    const char* str2 = "World";

    int result = myStrcmp(str1, str2);
	printf("%d\n",result);

        return 0;
}

 

 

 

 

你可能感兴趣的:(c语言,开发语言)