使用指向指针的指针对字符串排序
2014-12-08 10:52
239 查看
使用指向指针的指针对字符串排序
/****************************************
功能:使用指向指针的指针对字符串排序
日期:2014年12月8日10:49:33
*****************************************/
#include<stdio.h>
#include<string.h>
sort(char *strings[], int n)
{
char *temp;
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; 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(p, n);
for(i = 0; i < n; i++)
printf("%s\n",strings[i]);
}
/******************************
World wide
Hello world
Great wall
C language
Basic
Press any key to continue
******************************/
/****************************************
功能:使用指向指针的指针对字符串排序
日期:2014年12月8日10:49:33
*****************************************/
#include<stdio.h>
#include<string.h>
sort(char *strings[], int n)
{
char *temp;
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; 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(p, n);
for(i = 0; i < n; i++)
printf("%s\n",strings[i]);
}
/******************************
World wide
Hello world
Great wall
C language
Basic
Press any key to continue
******************************/
相关文章推荐
- 使用快速排序算法对字符串数组进行排序(复习指向指针的指针以及指针数组的使用)
- 使用指向指针的指针对字符串排序
- 使用指向指针的指针对字符串排序
- 用指向指针的指针对5个字符串进行排序
- 使用指针对字符串排序
- 用指针指向指针的方法对5个字符串排序并输出
- 用指向指针的指针对字符串进行排序
- 用指向指针方法对N个字符串进行排序并输出
- c++使用指针指向的字符串,如何判断字符串结束
- 【C语言】使用指向指针数据的指针变量,输出一组字符串
- 用指向指针方法对N个字符串进行排序并输出
- acm--不等长字符串排序(指向指针的指针)
- 使用一级指针排序一个字符串数组
- 习题 8.20 用指向指针的指针的方法对5个字符串排序并输出。
- P279_1012 用了典型的冒泡法对字符串排序。侧重指针应用,交换指针所指向的地址。
- 用指向指针方法对N个字符串进行排序并输出
- 用指向指针的指针的方法对字符串和整数排序
- 【C语言】指向指针的指针变量对字符串进行排序
- 用指向指针的指针来对数组排序(字符串)
- (转 )Delphi指针如何指向使用with开域语句创建的无名组件对象