69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXCHAR 5000 //最长处理5000个字符
char c[MAXCHAR], *a[MAXCHAR];
int comlen( char *p, char *q ){
int i = 0;
while( *p && (*p++ == *q++) )
++i;
return i;
}
int pstrcmp( const void *p1, const void *p2 ){ // 这个函数是什么意思,参数看不懂
return strcmp( *(char* const *)p1, *(char* const*)p2 );
}
int main( ){
char ch;
int n=0;
int i, temp;
int maxlen=0, maxi=0;
printf("Please input your string:\n");
while( (ch=getchar())!='\n' ){
a[n]=&c[n];
c[n++]=ch;
}
c[n]='\0';
qsort( a, n, sizeof(char*), pstrcmp ); // 这里的快速排序是对什么排序
for(i=0; i<n-1; ++i ){
temp=comlen( a[i], a[i+1] );
if( temp>maxlen ){
maxlen=temp;
maxi=i;
}
}
printf("%.*s\n",maxlen, a[maxi]);
system("PAUSE");
return 0;
}
int pstrcmp( const void *p1, const void *p2 ){ // 这个函数是什么意思,参数看不懂
return strcmp( *(char* const *)p1, *(char* const*)p2 );
}
是什么意思吗[/quote]
封装库函数接口而已!int pstrcmp( const void *p1, const void *p2 ){ // 这个函数是什么意思,参数看不懂
return strcmp( *(char* const *)p1, *(char* const*)p2 );
}
是什么意思吗