只要求输出最长的,所以没有必要把5个字符串都存储下来。举例如下:
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "string.h"
int main(void){
char a[100],la[100],i;
printf("please enter 5 strings...\n");
for(*la='\0',i=0;i<5;i++)
if(scanf("%s",a),strlen(a)>strlen(la))//总是保留较长的
strcpy(la,a);
printf("The longest string is %s\n",la);
printf("\n");
return 0;
}