#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* my_malloc();
void input(char* p);
int my_strcmp(const char* s1,const char* s2);
char* my_free(char* p);
int main(int argc, const char* argv[])
{
char* p1 = my_malloc();
char* p2 = my_malloc();
input(p1);
input(p2);
int sub = my_strcmp(p1,p2);
if (sub > 0)
printf("p1 > p2\n");
else if (sub < 0)
printf("p1 < p2\n");
else
printf("p1 = p2\n");
p1 = my_free(p1);
p2 = my_free(p2);
return 0;
}
char* my_malloc()
{
char* p = (char*)malloc(sizeof(char)*32);
return p;
}
void input(char* p)
{
printf("please input string:");
gets(p);
}
int my_strcmp(const char* s1,const char* s2)
{
while (*s1 == *s2)
{
if(*s1 == '\0')
break;
s1++;
s2++;
}
return *s1 - *s2;
}
char* my_free(char* p)
{
free(p);
p = NULL;
return p;
}
20240723 作业
最新推荐文章于 2024-08-22 21:24:01 发布