用C语言,输入一字母串,将其从小到大排列(如果输入字母为大写,要将其转换为对应的小写字母 c语言:从键盘输入一个字符串,将其中的的小写字母改为大写字母...
\u7528C\u8bed\u8a00\u7f16\u7a0b \u901a\u8fc7\u952e\u76d8\u8f93\u5165\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd,\u8981\u6c42\u5c06\u5176\u8f6c\u5316\u4e3a\u5bf9\u5e94\u7684\u5927\u5199\u5b57\u6bcd\u540e\u8f93\u51fa#include
void main(){
char word;
scanf("%c",&word);
a-=32;
printf("%c\n",word);
}
ASCII \u7801\u4f7f\u7528\u6307\u5b9a\u76847 \u4f4d\u62168 \u4f4d\u4e8c\u8fdb\u5236\u6570\u7ec4\u5408\u6765\u8868\u793a128 \u6216256 \u79cd\u53ef\u80fd\u7684\u5b57\u7b26\u3002\u6807\u51c6ASCII \u7801\u4e5f\u53eb\u57fa\u7840ASCII\u7801\uff0c\u4f7f\u75287 \u4f4d\u4e8c\u8fdb\u5236\u6570\uff08\u5269\u4e0b\u76841\u4f4d\u4e8c\u8fdb\u5236\u4e3a0\uff09\u6765\u8868\u793a\u6240\u6709\u7684\u5927\u5199\u548c\u5c0f\u5199\u5b57\u6bcd\uff0c\u6570\u5b570 \u52309\u3001\u6807\u70b9\u7b26\u53f7\uff0c \u4ee5\u53ca\u5728\u7f8e\u5f0f\u82f1\u8bed\u4e2d\u4f7f\u7528\u7684\u7279\u6b8a\u63a7\u5236\u5b57\u7b26\u3002\u5176\u4e2d\uff1a
0\uff5e31\u53ca127(\u517133\u4e2a)\u662f\u63a7\u5236\u5b57\u7b26\u6216\u901a\u4fe1\u4e13\u7528\u5b57\u7b26\uff08\u5176\u4f59\u4e3a\u53ef\u663e\u793a\u5b57\u7b26\uff09\uff0c\u5982\u63a7\u5236\u7b26\uff1aLF\uff08\u6362\u884c\uff09\u3001CR\uff08\u56de\u8f66\uff09\u3001FF\uff08\u6362\u9875\uff09\u3001DEL\uff08\u5220\u9664\uff09\u3001BS\uff08\u9000\u683c)\u3001BEL\uff08\u54cd\u94c3\uff09\u7b49\uff1b
\u901a\u4fe1\u4e13\u7528\u5b57\u7b26\uff1aSOH\uff08\u6587\u5934\uff09\u3001EOT\uff08\u6587\u5c3e\uff09\u3001ACK\uff08\u786e\u8ba4\uff09\u7b49\uff1bASCII\u503c\u4e3a8\u30019\u300110 \u548c13 \u5206\u522b\u8f6c\u6362\u4e3a\u9000\u683c\u3001\u5236\u8868\u3001\u6362\u884c\u548c\u56de\u8f66\u5b57\u7b26\u3002\u5b83\u4eec\u5e76\u6ca1\u6709\u7279\u5b9a\u7684\u56fe\u5f62\u663e\u793a\uff0c\u4f46\u4f1a\u4f9d\u4e0d\u540c\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u5bf9\u6587\u672c\u663e\u793a\u6709\u4e0d\u540c\u7684\u5f71\u54cd\u3002
32\uff5e126(\u517195\u4e2a)\u662f\u5b57\u7b26(32\u662f\u7a7a\u683c\uff09\uff0c\u5176\u4e2d48\uff5e57\u4e3a0\u52309\u5341\u4e2a\u963f\u62c9\u4f2f\u6570\u5b57\u3002
65\uff5e90\u4e3a26\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\uff0c97\uff5e122\u53f7\u4e3a26\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5176\u4f59\u4e3a\u4e00\u4e9b\u6807\u70b9\u7b26\u53f7\u3001\u8fd0\u7b97\u7b26\u53f7\u7b49\u3002
\u6839\u636eASCII\u6807\u51c6\u8868\u53ef\u770b\u51fa\u540c\u4e00\u5b57\u6bcd\u7684\u5927\u5199\u548c\u5c0f\u5199\u4e4b\u95f4\u76f8\u5dee32\u3002
\u6269\u5c55\u8d44\u6599\uff1a
1. 1981\u5e74IBM PC ROM256\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u96c6\uff0c\u5373IBM\u6269\u5c55\u5b57\u7b26\u96c6\u3002
2. 1985\u5e7411 Windows\u5b57\u7b26\u96c6\u88ab\u79f0\u4f5c\u201cANSI\u5b57\u7b26\u96c6\u201d\uff0c\u9075\u5faa\u4e86ANSI\u8349\u6848\u548cISO\u6807\u51c6\uff08ANSI/ISO8859-1-1987\uff0c\u7b80\u201cLatin 1\u201d\u3002
3. 1987\u5e744\u6708\u4ee3\u7801\u9875437,\u5b57\u7b26\u7684\u6620\u50cf\u4ee3\u7801\uff0c\u5728MS-DOS3.3\u51fa\u73b0\u3002
\u6269\u5c55ASCII \u5b57\u7b26\u662f\u4ece128 \u5230255\uff080x80-0xff\uff09\u7684\u5b57\u7b26\u3002
\u6269\u5c55ASCII\u4e0d\u518d\u662f\u56fd\u9645\u6807\u51c6\u3002
4. \u53cc\u5b57\u8282\u5b57\u7b26\u96c6\uff08DBCS\uff1adouble-byte character set\uff09,\u89e3\u51b3\u4e2d\u56fd\u3001\u65e5\u672c\u548c\u97e9\u56fd\u7684\u8c61\u5f62\u6587\u5b57\u7b26\u548cASCII\u7684\u67d0\u79cd\u517c\u5bb9\u6027\u3002DBCS\u4ece256\u4ee3\u7801\u5f00\u59cb\uff0c\u5c31\u50cfASCII\u4e00\u6837\u3002
\u4e0e\u4efb\u4f55\u884c\u4e3a\u826f\u597d\u7684\u4ee3\u7801\u9875\u4e00\u6837\uff0c\u6700\u521d\u7684128\u4e2a\u4ee3\u7801\u662fASCII\u3002\u7136\u800c\uff0c\u8f83\u9ad8\u7684128\u4e2a\u4ee3\u7801\u4e2d\u7684\u67d0\u4e9b\u603b\u662f\u8ddf\u968f\u7740\u7b2c\u4e8c\u4e2a\u5b57\u8282\u3002\u8fd9\u4e24\u4e2a\u5b57\u8282\u4e00\u8d77\uff08\u79f0\u4f5c\u9996\u5b57\u8282\u548c\u8ddf\u968f\u5b57\u8282\uff09\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u590d\u6742\u7684\u8c61\u5f62\u6587\u5b57\u3002
\u53c2\u8003\u8d44\u6599\uff1aASCII
\u4fe1\u606f\u5b66\u5965\u8d5b 1138-\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5b57\u6bcd
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int comp(const void*a, const void*b)
{
return (((char *)a)[0])-(((char *)b)[0]);
}
int main()
{
int len, i;
char str[100];
scanf("%s", str);
len = strlen(str);
for (i=0;i<len;i++) {
if ((str[i] >= 'A') && (str[i] <= 'Z'))
str[i] += 32; //字符大小写转化
}
qsort((void*)str,len,sizeof(char),comp); //对字符串进行快速排序
printf("%s
", str);
return 0;
}
先进行字符串大小写转换,再进行排序(当然你也可以换着来,把qsort
()语句提到for循环前面即可)。
#include <stdio.h>
#include <ctype.h>
#define MAX_SIZE 16
int insert(char ch, char str[])
{
int i;
char tmpch;
for(i=0; str[i]!='\0' && i< MAX_SIZE-1; i++)//插入排序法
{
if(ch<str[i])
{
tmpch= str[i];
str[i]= ch;
ch= tmpch;
}
}
str[i]= ch;
str[i+1]='\0';
return i< MAX_SIZE-1? 1: 0;
}
int main(int argc, char *argv[])
{
char ch=0;
char str[MAX_SIZE]="\0";
int result=1;
while(ch != '#' && result)//输入与井号结束
{
scanf("%c",&ch);
ch= tolower(ch);
result= insert(ch, str);
}
printf("%s
",str);
return 0;
}
I Like Eat Apple#
aaeeeiikllppt
请按任意键继续. . .
#include <stdio.h>
#include <string.h>
#define MaxSize 50
void TurnChar(char a[]);
void SortChar(char a[]);
void main()
{
char a[MaxSize];
printf("请输入字符串:");
gets(a);
TurnChar(a);
SortChar(a);
printf("\n排序后的字符串为:");
puts(a);
}
//转换字符串中大字字母为小写
void TurnChar(char a[])
{
char *p;
p=a;
while(*p!='\0')
{
if((*p>='A') && (*p<='Z'))
*p=*p+32;
p++;
}
}
//对字符串进行排序
void SortChar(char a[])
{
char *p,*q,t;
p=a;
q=p+1;
while(*p!='\0')
{
while(*q!='\0')
{
if(*q<*p)
{
t=*q;
*q=*p;
*p=t;
}
q++;
}
p++;
q=p+1;
}
}
运行过了,没有问题,望采纳,谢谢!!!!!!!
绛旓細include <stdio.h>#include <string.h>#include <stdlib.h>int comp(const void*a, const void*b){return (((char *)a)[0])-(((char *)b)[0]);}int main(){int len, i;char str[100];scanf("%s", str);len = strlen(str);for (i=0;i<len;i++) {if ((str[i] >= ...
绛旓細cout << "璇疯緭鍏ュ瓧绗︿覆:";gets_s(a);//鎸夌収鎻愮ず锛氬埄鐢ㄥ瓧绗﹁緭鍏ュ嚱鏁拌繘琛屽瓧绗涓茶緭鍏骞跺瓨鍒癮鏁扮粍涓 cout << "璇疯緭鍏:";cin >> m;//鎸夌収鎻愮ず锛氳緭鍏ユ寚瀹氬鍒跺厓绱犺捣濮嬪潗鏍 for (i = 0; b[i - 1] != '\0'; i++)//閬嶅巻浠庢寚瀹氬厓绱犲紑濮嬶紝鍒板瓧绗︿覆缁撴潫鍋滄 { b[i] = a[i + m -...
绛旓細int main (){ void copystr(char *,char *,int);int m;char str1[20],str2[20];printf("input string:");gets(str1);printf("which character that begin to copy?");scanf("%d",&m);if(strlen(str1) < m){ printf("input error!");} else { copystr(str1,str2,m);printf...
绛旓細include <stdio.h>int main(void){ char str[300],w[21],i,j,k; printf("Input a string...\nstr="); gets(str); for(j=0;str[j];j++); for(j--;str[j]>'z' || str[j]<'a' && str[j]>'Z' || str[j]<'A';j--); for(i=j;str[i]>='A...
绛旓細include<stdio.h>char toupper(char c){ if(c>='a'&&c<='z')c-=32; return c;}int main(){ char s[200]; int i; gets(s); for(i=0; s[i]; i++) s[i]=toupper(s[i]); printf("%s\n",s); return 0;} ...
绛旓細while(n--){ s1++;} s1鏄痗har * 绫诲瀷鐨勶紝 浣犳妸s1鎯虫垚鏄細 char s1[m+n]鐨勪竴涓暟缁勶紝 s1++ 鐩稿綋浜庝粠s1[0]--->s1[1] ; 鐢╳hile(n --) 鍒欑Щ鍔ㄤ簡n娆★紝鍒欑Щ鍒颁簡s1[n-1]浣嶇疆
绛旓細exit(1);} str2=mcopy(str1,m); //绋嬪簭鐨勮皟鐢 for(int j=0;j<strlen(str2);j++) //鎶婃暟缁勮繘琛岃緭鍑 printf("瀛楃涓茬%d涓厓绱犳槸%c\n",m++,str2[j]); //瀛楃鐨勮緭鍑 } char *mcopy(char*s ,int m){ static char array[100];int count=0;for(int i=m-1;i<strlen(s)...
绛旓細void main(){ printf("璇杈撳叆涓涓插瓧姣:\n");char s[100];scanf("%s",&s);for(int i = 0;s[i] != '\0';i ++){ if(s[i]>='a'&&s[i]<'w')s[i] += 4;else if(s[i]>='w'&&s[i]<='z')s[i] = 'a'+s[i]-'w';} printf("鍙樺寲鍚庣殑瀛楃涓蹭负锛%s\n",s)...
绛旓細1銆佹垜浠紪杈戝鍥句腑杈撳叆鐨勪唬鐮併2銆佽繘鍏ユ簮鏂囦欢鐨勭洰褰曚笅锛屽湪缁堢杈撳叆鍛戒护gcc -o t test.cpp銆3銆佽緭鍏./t鍛戒护锛岃繍琛岀敓鎴愮殑鍙墽琛屾枃浠躲4銆佽繍琛岀粨鏋滀负baidu銆5銆乻trncpy 鐨勫嚱鏁板師鍨媍har *strncpy(char *dest,char *src,size_t n)锛屾垜浠湪澶嶅埗src鐨勫墠n涓瓧绗﹀埌dst涓6銆佸鏋滆秴杩噑rc鐨勫瓧绗︿覆闀垮害锛...
绛旓細浠ヤ竴涓8涓哄瓧绗涓涓轰緥锛氫唬鐮佸涓 include<stdio.h> int main(){ int i,j;char ch1[8],ch2[8];for(i=0;i<8;i++){ printf("璇杈撳叆绗%d涓瓧绗",i);scanf("%c",&ch1[i]);fflush(stdin);} for(j=0;j<8;j++){ ch2[j]=ch1[7-j];printf("%c",ch2[j]);} } ...