C语言 手写 strcpy/strcmp/strlen/strcat

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

void my_strcpy(char*p,char*q)
{
  while(*q !='\0')
  { 
    *p=*q;
	p++;
	q++;
  }
  *p=*q;
}
int my_strlen(char *q)
{
 int count=0;
 for(int i=0;q[i] !='\0';i++)
 {
  count++;
 }
  return count;
}
int my_strcmp(char *str1,char *str2)
{
 int i = 0;
    while (str1[i] != '\0' || str2[i] != '\0')
    {
        if (str1[i] != str2[i])
        {
            return str1[i] - str2[i];
        }
        i++;
    }
    return 0;
}
char* my_strcat(char *q,char *p)
{
  int n=strlen(q);
  for(int i=0;p[i]!='\0';i++)
  {
    q[n]=p[i];
	n++;
 }
  q[n]='\0';
  return q;
}
int main(int argc, const char *argv[])
{
	strcpy复制//
	/*
	char buf []="hello";
	char arr []="world";
	my_strcpy(buf,arr);
	printf("%s\n",buf);
	*/
	///my_strlen长度不算\0///
	/*
	char arr[]="hello";
	int n;
	n=my_strlen(arr);
	printf("长度%d\n",n);
	*/
	///my_strcmp比较/
    /*
	char buf[]="he";
	char arr[]="ha";
	int n=my_strcmp(buf,arr);
	if(n>1)
	{
	 printf("buf>arr\n");
	}else if(n==0)
	{
	 printf("一样大\n");
	}else if(n<-1)
	{
		printf("buf

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