📄 exp07_06.c
字号:
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char str[80];
char **pstr;
int i,j,k,num;
printf("input the number:");
scanf("%d",&num);
fflush(stdin);
pstr=(char **)malloc(num*sizeof(char *));
if(pstr==NULL)
{
printf("No enough memory\n");
return;
}
for(i=0;i<num;i++)
{
printf("input the name of the %dth student:",i+1);
gets(str);
if(strlen(str)>19)
{
i--;
continue;
}
pstr[i]=(char *)malloc(strlen(str)+1);
if(pstr[i]==NULL)
{
printf("No enough memory\n");
exit(-1);
}
strcpy(pstr[i],str);
}
for(j=1;j<=num-1;j++)
{
k=num-j;
for(i=0;i<num-j;i++)
if(stricmp(pstr[i],pstr[k])>0)
k=i;
if(k!=num-j)
{
char *ptmp;
ptmp=pstr[k];
pstr[k]=pstr[num-j];
pstr[num-j]=ptmp;
}
}
for(i=0;i<num;i++)
printf("%dth:%s\n",i+1,pstr[i]);
for(i=0;i<num;i++)
free(pstr[i]);
free(pstr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -