使用指向指针的指针对字符串排序
2015-10-02 10:06
267 查看
/* title:使用指向指针的指针对字符串排序 author:王玉杰 time:2015年10月2日09:48:15 */ #include<stdio.h> #include<string.h> sort(char *strings[],int n) { char *temp; int i,j; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(strcmp(strings[i],strings[j])>0) { temp=strings[i]; strings[i]=strings[j]; strings[j]=temp; } } } } void main() { int n=5; int i; char **p; char *strings[]={"C language","Basic","World wide","Hello world","Great Wall"}; //定义指针数组,数组中存的是个指针,然后指针指向一个字符串,就像字符串指针一样,只有只读属性,无法对其内容操作 p=strings; sort(strings,n); for(i=0;i<5;i++) { printf("%s\n",strings[i]); } }
相关文章推荐
- HDU 4276 The Ghost Blows Light
- Git 分支管理
- nyoj-40 公约数和公倍数【辗转相除法】
- (ZT)在int13h中使用es:bx的例子
- POJ3184 Ikki's Story I - Road Reconstruction(最大流)
- POJ 3074 Sudoku (DLX解经典数独)
- 杂七杂八
- Linux Shell 之 Shell 打印命令
- linux避免僵死进程方法总结 http://blog.csdn.net/astrotycoon/article/details/39717143
- 深入理解按位异或运算符
- 第二次作业
- POJ 3159 【朴素的差分约束】
- codeforces 478D D. Red-Green Towers(dp)
- scrapy学习--内置Spiders简介
- 买股票最大利润
- 补码
- 【IOS 开发学习总结-OC-28】★objective-c之foundation 框架——集合类的综述
- this关键字与super关键字
- kmp算法原理及实现
- waitpid(or wait)和SIGCHILD的关系 http://blog.csdn.net/liuxingen/article/details/38350347