求助!利用指针,字符比大小的问题。。。。。。。。。。。




大家看看哪错了哦,书上是直接用数组比的,我想下,以前学过调用函数比数字大小,所以想做做看

#include<stdio.h> #include<string.h> char max(char *p,char *k); void main() { char string[20]; char str[3][20]; int i; printf("请输入3个字符:\n"); for(i=0;i<3;i++) { scanf("%s",str[i]); //输入3个字符 } strcpy(string,max(str[2],max(str[0],str[1]))); //嵌套使用max函数比较字符大小 printf("\n你输入的3个字符中最大的字符是:\n%s",string); getch(); } char max(char *p,char *k) //实现max函数环节 { char temp[20]; if(strcmp(p,k)>0) strcpy(temp,p); else strcpy(temp,k); return temp; //返回最大值 }
[ 本帖最后由 ab6326795 于 2011-5-29 22:27 编辑 ]