qq_龙戈_0
2018-04-08 08:17
#include <stdio.h>
#include <string.h>
int main()
int i,m;
char*bname[]={"Programming inANSI C","BASIC","Visual C++ 6.0Programming","TURBO C 2.0"};
void sort(char*name[],int);
m=sizeof(bname)/sizeof(char*);
sort(bname,m);
putchar('\0');
for(i=0;i<m;i ++)
{
printf("%s",bname[i]);
}
return 0;
sort (char*name[].int n)
{
char*t;
int i,j,k;
for(i=O;i<n-1 ;i ++)
k=i ;
{
for(j=i+1 ;j<n) ;
if(strcmp(name[k],name[j)>
k=j;
{
if(k!=i)
t=name[i];
name[i]=name[k];
name[k]=t;
}
}
}
// 题目是有若干本书,将其书名按字典顺序排序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sort(char*name[],int m)
{
char*t;
int i,j,k;
for(i=0;i<m-1 ;i++){
k=i;
for(j=i+1 ;j<m;j++){
if(strcmp(name[k],name[j])>0){
k=j;
}
if(k!=i){
t=name[i];
name[i]=name[k];
name[k]=t;
}
}
}
int main()
{
char*bname[]={"Programming inANSI C","BASIC","Visual C++ 6.0Programming","TURBO C 2.0"};
m=sizeof(bname)/sizeof(char*);
sort(bname,m);
putchar('\0');
for(i=0;i<m;i ++){
printf("%s\n",bname[i]);
}
printf("Hello world!\n");
return 0;
}
Linux C语言指针与内存
116475 学习 · 250 问题
相似问题