//【E11_2.c】 输入三个字符串,利用字符串处理的相关函数,求出其中的最大者。 //字符串输入输出函数:gets(),puts() //字符串赋值函数:strcpy(),strcat() //字符串比较函数:strcmp() /* 输入: I am a student I am learning C programing I hope to get good result 输出: The MAX string is: I hope to get good result */ #include
#include
void main() { char str[3][40]; //存放三个字符串;注意单个字符串长度不得大于40 char maxstr[40]; //存放最大字符串 int i; //输入三个字符串分别放到str[0],str[1],str[2] printf("Please input 3 strs(End with Enter):\n"); for(i=0;i<3;i++) { gets(【空1】); } //分行输出三个字符串 printf("You just input the 3 strs are:\n"); for(i=0;i<3;i++) { puts(str[i]); } //寻找最大的字符串 printf("Now will finding the MAX string...\n"); if(【空2】) //比较str[0],str[1] strcpy(maxstr,str[0]); else strcpy(maxstr,str[1]); if(strcmp(str[2],maxstr)>0) 【空3】; //得到maxstr的最终赋值 //输出最大的字符串 printf("The MAX string is:\n%s\n",maxstr); }