c语言中如何实现从键盘中输入一个字符串设计函数sort函数实现该串中字符按从大到小输出? 要求通过键盘输入5串字符串,然后调用函数sort完成字符串从...
C\u8bed\u8a00\u8981\u6c42\u901a\u8fc7\u952e\u76d8\u8f93\u51655\u5b57\u7b26\u4e32\uff0c\u518d\u8c03\u7528\u51fd\u6570sort\u7ed9\u5b57\u7b26\u4e32\u4ece\u5c0f\u5230\u5927\u6392\u5217\uff0c\u518d\u8c03\u7528print\u51fd\u6570\u5b8c\u6210\u5b57\u7b26\u4e32\u8f93\u51fa\u3002\u770b\u4f60\u4ee3\u7801\u539f\u610f\uff0c\u662f\u60f3\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4strs\u3002
\u4f46\u662f\u4f60\u5199\u7684char *strs[5];\u8868\u793a\u7684\u662f\u4e00\u4e2a\u7ef4\u5ea6\u4e3a5\u7684\u6307\u9488\u6570\u7ec4\u3002
\u4f60\u53ef\u4ee5\u628astrs\u76f4\u63a5\u6539\u6210\u5b57\u7b26\u4e32\u6570\u7ec4\uff0cchar strs[5][N]\uff0c\u4f46\u4f60\u540e\u9762\u7684\u51fd\u6570\u53c2\u6570\u7c7b\u578b\u4e5f\u8981\u8ddf\u7740\u6539\u3002
\u5982\u679c\u4f60\u4e0d\u60f3\u6539\u52a8\u5176\u4ed6\u51fd\u6570\uff0c\u8fd8\u7ee7\u7eed\u4f7f\u7528\u6307\u9488\u6570\u7ec4\uff0c\u4e5f\u662f\u53ef\u4ee5\u7684\u3002
\u4f60\u53ef\u4ee5\u7528\u52a8\u6001\u5185\u5b58\u6765\u5199\u8f93\u5165\u90e8\u5206\uff1a\uff08\u5934\u6587\u4ef6\u6dfb\u52a0malloc.h\uff09
#include #include #define N 100//\u6bcf\u4e2a\u5b57\u7b26\u4e32\u6700\u5927\u957f\u5ea6int main(){ int i; char *strs[5]; for(i=0;i<5;i++) { strs[i]=(char *)malloc(sizeof(char)*(N+1)); if(strs[i]) scanf("%s",strs[i]); else { printf("\u9519\u8bef\u5185\u5b58\u7533\u8bf7\u5931\u8d25\uff01\n"); return 1; } } return 0;}
printf("%s\n",*name[i]);
\u8fd9\u53e5\u591a\u4e86\u4e00\u4e2a\u661f\u53f7\uff0c\u5e94\u8be5\u662f
printf("%s\n",name[i]);
#include<stdio.h>
#include<string.h>
int sort(char a[])
{
for(int i=0;i<strlen(a);i++)
for(int j=0;j<strlen(a)-i-1;j++)
if(a[j]<a[j+1])
{
char t;
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
for(int i=0;i<strlen(a);i++)
printf("%c ",a[i]);
}
int main()
{
char a[111];
gets(a);
sort(a);//调用函数
return 0;
}
绛旓細鍦–璇█涓疄鐜扮敤閿洏杈撳叆涓涓瓧绗︿覆锛屽苟鎵撳嵃鍑烘潵鐨勮В鍐虫柟娉曞涓嬶細1銆侀鍏堝畾涔変竴涓瓧绗︿覆鏁扮粍锛屽浣犲彲浠ョ粰瀛楃涓100涓暟缁勭┖闂銆傚鍥炬嫭鍙峰唴鏁板瓧鍗充负浣犲畾涔夌殑鏁扮粍澶у皬銆2銆乬ets()鍑芥暟鐢ㄦ潵鑾峰彇閿洏杈撳叆鐨勫瓧绗︿覆锛屾嫭鍙峰唴鐨剆鍗充负瀛楃涓插彉閲忋3銆佹帴鐫鐢╬uts锛堬級鍑芥暟杈撳嚭涔嬪墠鎴戜滑浠庨敭鐩樿鍙栫殑瀛楃涓层傛嫭鍙峰唴涓...
绛旓細1銆侀鍏堥渶瑕佹墦寮缂栫▼杞欢銆2銆佽緭鍏ヤ互涓嬬▼搴忥細#include <stdio.h>int main(){ char str[40]; scanf("%s",&str); printf("%s",str); return 0;}銆3銆佺劧鍚庢寜F5杩愯绋嬪簭銆4銆佺劧鍚庤緭鍏ユ兂瑕杈撳叆鐨瀛楃涓层5銆佹寜鍥炶溅閿紝灏变細寮瑰嚭浣犺緭鍏ョ殑瀛楃涓层6銆佹敞鎰忓瓧绗︿覆鐨勫ぇ灏忥紝鏀瑰彉涓嫭鍙蜂腑鐨勬暟瀛楁敼鍙樿緭鍏...
绛旓細printf("1鍒%d涔嬮棿鎵鏈変釜浣嶆暟鏄3鎴5鐨勬暟鐨勫拰涓猴細%d\n", n, sum);return 0;} 鍦ㄨ繖涓▼搴忎腑锛屾垜浠娇鐢 for 寰幆閬嶅巻浠 1 鍒 n 鐨勬墍鏈夋暣鏁帮紝鍒ゆ柇瀹冧滑鐨勪釜浣嶆暟鏄惁涓 3 鎴 5锛屽鏋滄槸锛屽垯灏嗗畠浠殑鍜岀疮鍔犲埌鍙橀噺 sum 涓傛渶缁堣緭鍑哄彉閲 sum 鐨勫硷紝鍗充负棰樼洰鎵姹傘傞渶瑕佹敞鎰忕殑鏄紝棰樼洰瑕佹眰杈撳叆涓...
绛旓細1.棣栧厛闇瑕佸厛瀹氫箟涓涓瓨鏀惧瓧绗︿覆鐨勬暟缁勭┖闂达紝濡傜粰瀛楃涓100涓暟缁勭┖闂銆2.鎺ョ潃浣跨敤gets()鍑芥暟鏉ヨ幏鍙栭敭鐩樿緭鍏ョ殑瀛楃涓层備竴鑸牸寮忎负gets(瀹氫箟鐨勫瓧绗︽暟缁勫悕)銆3.鐒跺悗鍐嶄娇鐢╬uts()鍑芥暟鏉ヨ緭鍑轰箣鍓嶈緭鍏ョ殑瀛楃涓插唴瀹广備竴鑸牸寮弍uts锛堝畾涔夌殑瀛楃鏁扮粍鍚嶏級銆4.鏈缁堣繍琛岀▼搴忥紝鍗冲彲鎴愬姛瀹炵幇杈撳叆瀛楃涓诧紝鐒跺悗鍘熸牱鍦ㄥ睆...
绛旓細C璇█浠庨敭鐩樿緭鍏浠绘剰鐨10涓暣鏁帮紝浠庝腑鎵惧嚭鏈澶у煎拰鏈灏忓肩殑鍏蜂綋姝ラ濡備笅锛1銆侀鍏堣緭鍏 include<stdio.h> int main(){ int arr[10] = {0};int i = 0;int max = 0;int min = 0;printf("璇疯緭鍏10涓暣鏁帮細");2銆佺劧鍚庤緭鍏 for (i = 0; i < sizeof(arr)/ sizeof(arr[0]); i+...
绛旓細绋嬪簭婧愮爜濡備笅锛歞efine _CRT_SECURE_NO_WARNINGS//VS鐜涓嬮渶瑕侊紝VC涓嶉渶瑕 include<stdio.h> void main(){ char a;//瀹氫箟涓涓瓧绗 printf("璇杈撳叆涓涓瓧绗︼細");//鏂囧瓧鎻愮ず scanf("%c", &a);//杈撳叆涓涓瓧绗 printf("鍏跺悗缁瓧绗︿负锛");//鏂囧瓧鎻愮ず printf("%c\n", a + 1);//杈撳嚭鍏...
绛旓細//閫愪釜瀛楃杈撳叆瀛楃涓诧紝鍙互杈撳叆int鍙互琛ㄧず鐨勬渶澶у间釜瀛楃 printf("璇疯緭鍏ヤ换鎰忎釜瀛楃:\n");while(true){ scanf("%c",&input);if(input != '#'){ if((input >= 'A' && input <= 'Z') || (input >= 'a' && input <= 'z')){ if(charNum > strSize){ strSize += 100;s...
绛旓細鎬濊矾锛氬畾涔変竴涓瓧绗︽暟缁勶紝鍒╃敤璇ユ暟缁勬帴鏀閿洏杈撳叆鐨鏁存暟锛屾帴鐫渚濇閬嶅巻璇ユ暟缁勫苟杈撳嚭銆傚弬鑰冧唬鐮侊細include "stdio.h"int main(){ int i;char a[100];gets(a);//鎺ユ敹閿洏杈撳叆 printf("%c",a[0]);//鍏堣緭鍑虹涓涓瓧绗 for(i=1;a[i]!='\0';i++)//鎺ョ潃杈撳嚭鍚勪釜瀛楃 printf("$%c"...
绛旓細include <stdio.h> include <conio.h> void main(void){ char ch;int sum = 0;while((ch=getche())!='\r')//鎸変笅鍥炶溅閿紝閫鍑鸿鍏ワ紝骞惰緭鍑虹粨鏋 { if (ch>='0'&&ch<='9'){ sum += ch - '0';} } printf("\n%d\n",sum);} ...
绛旓細鍙互鍙傝冧笅闈㈢殑浠g爜锛歩nclude <stdio.h> void main(){ char ch;scanf("%c",&ch);if(ch>='A'&&ch<='Z'){ ch=ch+32;printf("%c\n\n",ch);}else{ printf("%c\n\n",ch);} }