可是...最近看C++看的.有点连带C了.C++不允许..可是...我记得....我再想想....
[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
程序大体上没问题,都是些小毛病.修改后:
#include <stdio.h>
#include <stdlib.h>
int compare_integers( void const*a,void const *b );
int main(int argc, char *argv[])
{
int *array;
int n_values;
int i;
printf("how many values are there?\n");
if( scanf("%d",&n_values)!=1||n_values<=0 ){
printf("Illegal number of values.\n");
exit(EXIT_FAILURE);
}
array=malloc(n_values*sizeof(int));
if( !array ){
printf("Can't get memory for that many values.\n");
exit(EXIT_FAILURE);
}
printf("please input these numbers:\n");
for( i=0;i<n_values;i+=1 ){
if( !scanf("%d",&array[i]) ){
printf("Error reading value #%d\n",i);
free(array);
exit(EXIT_FAILURE);
}
}
qsort( array ,n_values ,sizeof(int),compare_integers );
for( i=0;i<n_values;i++)
printf("%d\n",array[i]); getch();
free(array);
return EXIT_SUCCESS;
system("PAUSE");
return 0;
}
int compare_integers( void const*a,void const *b )
{
register int const *pa=a;
register int const *pb=b;
return *pa>*pb?1:*pa<*pb?-1:0;
}
[此贴子已经被作者于2006-8-15 9:13:55编辑过]