#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *create(){
char *p=(char *)malloc(sizeof(char)*100);
if(p==NULL){
return NULL;
}
return p;
}
int mystrcmp(char *str1,char *str2){
char *p=str1,*q=str2;
while(str1){
if(*p==*q){
p++;q++;
}else{
return *p-*q;
}
}
}
void mystrcat(char *str1,char *str2){
char *p=str1,*q=str2;
while(*p){
p++;
}
while(*q){
*p++=*q++;
}
*p='\0';
printf("%s\n",str1);
}
void mystrcpy(char *str1,char *str2){
char *p=str2;
int i=0;
while(*p){
*(str1+i)=*p++;
i++;
}
*(str1+i)='\0';
printf("%s\n",str1);
}
int main(int argc, const char *argv[])
{
//堆区申请空间
char *str1=create();
char *str2=create();
printf("输入str1:");
scanf("%s",str1);
printf("输入str2:");
scanf("%s",str2);
//比较
if(mystrcmp(str1,str2)>0){
printf("str1大\n");
}else{
printf("str2大\n");
}
//连接
mystrcat(str1,str2);
//拷贝
mystrcpy(str1,str2);
return 0;
}
数据结构day1
最新推荐文章于 2025-11-23 20:57:51 发布
648

被折叠的 条评论
为什么被折叠?



