天天看點

C語言比較最長字元串

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define N 20

char *fun(char (*a)[20],int m,char *max)
{
  int i,j,k;
  max=a[0];
  for(i=0;i<m;i++)
  {
   if(strlen(a[i])>strlen(max))
	   max=a[i];
  }
  return max;
}
void main()
{   int i=0,j=0;char *ps=NULL;
    char ss[5][20]={""};
    while(i<5)
	{
	 gets(ss[i]);
	 i++;
	}
	ps=fun(ss,i,ps);
	printf("Maxstring=%s",ps);
	system("pause");
}