1.定义两个字符指针,配指向堆空间,实现字符串比较,释放
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
char *p1;
char *p2;
int i=0,k;
p1=(char*)malloc(50);
if(p1==NULL)
{
printf("p1 is NULL\n");
return -1;
}
p2=(char*)malloc(50);
if(p2==NULL)
{
printf("p2 is NULL\n");
return -1;
}
gets(p1);
gets(p2);
while(*(p2+i)==*(p1+i))
{
i++;
}
k=*(p1+i)-*(p2+i);
if(k>0)
printf("str1>str2\n");
else if(k<0)
printf("str1<str2\n");
else
printf("str1=str2\n");
free(p1);
p1=NULL;
free(p2);
p2=NULL;
return 0;
}