从键盘输入一个字符串放在字符数组…
2014-01-13 16:09
323 查看
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inOrder(char array[], int n );
int main(int argc, char *argv[])
{
char
temp[100];
printf("请输入字符串:\n");
gets(temp);
char
a[strlen(temp)+1];
strcpy(a,temp);
inOrder(a,strlen(temp));
int k;
for(k=0;
k<strlen(temp); k++)
{
printf("%c",a[k]);
}
system("pause");
return
0;
}
//选择法排序函数
void inOrder(char array[], int n)
{
int i,
j;
char temp;
for(i=0;
i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(array[j]>array[i])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
#include <stdlib.h>
#include <string.h>
void inOrder(char array[], int n );
int main(int argc, char *argv[])
{
char
temp[100];
printf("请输入字符串:\n");
gets(temp);
char
a[strlen(temp)+1];
strcpy(a,temp);
inOrder(a,strlen(temp));
int k;
for(k=0;
k<strlen(temp); k++)
{
printf("%c",a[k]);
}
system("pause");
return
0;
}
//选择法排序函数
void inOrder(char array[], int n)
{
int i,
j;
char temp;
for(i=0;
i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(array[j]>array[i])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
相关文章推荐
- 编写一个函数,由实参传来一个字符串,统计此字符串中字母,数字,空格,和其他字符的个数,在主函数中输入字符串以及输出上述统计的结果。再考虑将算的的结果放在一个数组中
- 汇编语言: 从键盘上输入一串字符(用回车键结束,使用 10 号功能调用。)放在 STRING 中,试 编制一个程序测试字符串中是否存在数字。如有,则把 CL 的第 5 位置 1,否则将该位置置 0。
- 输入一个字符串,内有数字和非数字字符,例如 A123x456 17960? 302tab5876 操作:将连续的数字作为一个整数,一次存放到一数组a中,例如123存放在a【0】中,456放在a【1】中
- 在java中如何用键盘输入一个数,字符,字符串
- 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉
- 从键盘输入一个字符串,将此字符串按字符的ASCII码值从小到大排序,并显示排序后的字符串。
- 输入一个字符串内有数字和非数字字符,将连续的数字作为一个整数,存到数组a中,统计整数的个数,并输出这些数
- 键盘输入字符串并将其转为字符数组
- 从键盘输入一个带有数字的字符串,将其中所在的数字的位置输出,并把数字串小写字符变大写字符再输出
- 在java中如何用键盘输入一个数,字符,字符串 (转)
- 输入一个字符串,内有数字和非数字字符,将其中连续的数字作为一个整数,依次存放到一数组a中。统计共有多少个整数,并输出这些数。
- 字符串替换空格: 请实现一个函数,把字符数组中的每个空格替换成“%20”。 例如输入“we are happy.”,则输出“we%20are%20happy.”。
- 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。
- 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。
- 从键盘输入一个字符串,按照字符顺序从小到大进行排序,并要求删除重复的的字符。
- 习题 8.16 输入一个字符串,内有数字和非数字字符,将其中连续的数字作为一个整数,依次存放到一数组a中。统计共有多少个整数,并输出这些数。
- 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。 压缩规则: 1、仅压缩连续重复出现的字符。比如字符串"abcbc
- 从键盘上输入一个字符串并保存在str1中,并把str1中下表为偶数的字符保存到str2中
- 在java中如何用键盘输入一个数,字符,字符串
- 从键盘接收一个字符串, 程序对其中所有字符进行排序,例如键盘输入: helloitcast程序打印:acehillostt