定义两个字符指针,分配指向堆区空间,实现字符串比较,释放
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
int my_strcom(char *a,char *b)
{
int result = 0;
while(*a !='\0' && *b !='\0' && *a == *b)
{
a++;
b++;
}
result = *a-*b;
return result;
}
int main(int argc, const char *argv[])
{
//char arr[30] = "hello";
//char brr[30] = "world";
char *pa = (char *)malloc(sizeof(char)*100);
char *pb = (char *)malloc(sizeof(char)*100);
//pa = arr;
//pb = brr;
printf("pa:");
gets(pa);
printf("pa:");
gets(pb);
int i=my_strcom(pa,pb);
printf("%d\n",i);
free(pa);
pa = NULL;
free(pb);
pb = NULL;
return 0;
}