输入一个字符串,只取其中的英文字母,全部转换成小写后输出。这个用C语言怎么编写? 这C语言程序如何编写,请大神指教。输入一个字符串,只取其中的...
\u95ee\u4e00\u4e2aC\u8bed\u8a00\u7684\u95ee\u9898\u3002\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ea\u53d6\u5176\u4e2d\u7684\u82f1\u6587\u5b57\u6bcd\uff0c\u5168\u90e8\u8f6c\u6362\u6210\u5c0f\u5199\u540e\u8f93\u51fa\u3002\u4f60\u7684\u5faa\u73af\u5faa\u73af\u4e86100\u6b21\u554a\uff0c\u4f46\u4f60\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u5374\u6ca1\u6709\u8fd9\u4e48\u957f\uff0c\u6240\u4ee5\u6ca1\u6709\u8d4b\u503c\u7684\u90a3\u4e00\u90e8\u5206\u7b97\u5165\u5176\u4ed6\u4e2d\u4e86\u3002
\u5e94\u8be5\u8fd9\u6837\u5199
for(i=0;a[i]!='\0';i++)
int main(){char c;char buf[256] = {0};int i = 0;while((c=getchar())!= '\n'){if(c >= 'a' && c = 'A' && c <= 'Z'){buf[i] = c + 'a' - 'A';i++;}}for(int n = 0; n < i; n ++){printf("%c ", buf[n]);}return 0;}
楼上说的不错到百度去科普了一下发现了一个小问题原型:extern char *strlwr(char *s);
用法:#include <string.h>
功能:将字符串s转换为小写形式
说明:只转换s中出现的大写字母,不改变其它字符。返回指向s的指针。
注意事项:在Linux的编译器中,有可能会编译不通过。
替代函数:
#include<ctype.h>
inline char* strlwr( char* str )
{
char* orig = str;
// process the string
for ( ; *str != '\0 '; str++ )
*str = tolower(*str);
return orig;
}
#include<stdio.h>
int main(void)
{
char a;
while((a=getchar())!='\n')
{if(a>='a'&&a<='z')
printf("%c",a);
else if(a>='A'&&a<='Z')
printf("%c",a+32);
}
}
#include<stdio.h>
#include<string.h>
int main()
{
char s[200];
gets(s);//scanf("%s",s);
strlwr(s);
char *p = s;
while(*p)
{
if(('a' > *p) || ('z' < *p))
{
int i = 0;
do
{
p[i] = p[i + 1];
}while('\0' != p[i++]);
}
else
{
++p;
}
}
printf(s);
return 0;
}
绛旓細include<stdio.h> include<string.h>//strlen鍑芥暟鐨勫ご鏂囦欢 int main(){ char a[111];int len=0;scanf("%s",a);len=strlen(a);//瀛楃涓闀垮害 for(int i=0;i<len;i++)if(a[i]>='A'&&a[i]<='Z'||a[i]>='a'&&a[i]<='z')printf("%c",a[i]);return 0;} ...
绛旓細杈撳叆涓琛屽瓧绗﹀垎鍒粺璁★紝鍑鍏朵腑鑻辨枃瀛楁瘝绌烘牸鏁板瓧鍜屽叾浠瀛楃鐨涓暟鐨勬簮浠g爜濡備笅锛歩nclude<stdio.h> int main(){ char c;int letters=0,spaces=0,digits=0,others=0;printf("璇疯緭鍏ヤ竴浜涘瓧姣嶏細\n");while((c=getchar())!='\n'){ if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))letters...
绛旓細棰樹富浣犲ソ,浠g爜鍙婃祴璇曟埅鍥惧涓:a.杈撳嚭涓哄皬鍐欏瓧姣:--- b.杈撳嚭涓哄ぇ鍐欏瓧姣:--- c.鍏跺畠渚嬪瓙:鍐欏湪鏈鍚: 涓婇潰缁欑殑浠g爜宸埆灏卞湪浜巙pper()鍑芥暟鍙妉ower()鍑芥暟, 鑰杈撳叆娌″暐闄愬埗, 鍏夊瓧姣,鎴栨眽瀛楀瓧姣嶆贩鐫绛夐兘娌¢棶棰. 浣嗕唬鐮佸啓鐨勪笉鏄お濂,鍙槸灏嗗熀鏈殑閫昏緫瀹炵幇浜 甯屾湜鍙互甯埌棰樹富, 娆㈣繋杩介棶 ...
绛旓細閿欒浠g爜锛歩f('a'<=nextchar<='z'||'A'<=nextchar<='Z')else if('0'<=nextchar<='9')淇敼鍚庯細include <stdio.h> int main(){ int letter=0,space=0,number=0,others=0;char nextchar;printf("Input your string\n");for(;nextchar!='\n';){ scanf("%c",&nextchar);if('a'...
绛旓細include <stdio.h>int main(){ char s1[200],s2[200]; int i,j; gets(s1); for(i=j=0; s1[i]; i++) if(s1[i]>='A'&&s1[i]<='Z') s2[j++]=s1[i]; s2[j]='\0'; printf("%s\nlen=%d\n",s2,j); return 0;} ...
绛旓細s[i]<='Z' && s[i]>='A')ch++;else n++;i++;} printf("鍒氭墠杈撳叆鐨勫瓧绗涓鑻辨枃瀛楃涓暟涓 %d\n", ch);printf("鍒氭墠杈撳叆鐨勫瓧绗︿腑绌烘牸涓暟涓 %d\n", space);printf("鍒氭墠杈撳叆鐨勫瓧绗︿腑鏁板瓧涓暟涓 %d\n", num);printf("鍒氭墠杈撳叆鐨勫瓧绗︿腑鍏朵粬涓暟涓 %d\n", n);return 0;} ...
绛旓細include <stdio.h>void main(){ int letter, space, digit, other; char ch; letter = space = digit = other = 0; while ((ch = getchar ()) != '\n') { if (ch>='a' && ch <= 'z' || ch>='A'&&ch<='Z') letter++; else if (ch>='0' && ch <='9')...
绛旓細include <stdio.h>int main(void){char a[10]={0,0,0,0,0,0,0,0,0,0},b[10]={0,0,0,0,0,0,0,0,0,0},c=0;int i=-1,j=0,k=0;do{i++; scanf("%c",&a[i]);c=a[i];if((c>='A')&&(c<='Z')||(c>='a')&&(c<='z')){b[j]...
绛旓細鍦‥XCEL琛ㄦ牸澶勭悊涓紝甯稿父闇瑕佸湪瀛楃涓蹭腑鎻愬彇閮ㄥ垎瀛楃锛浠ヨ繘琛屼笅涓姝ュ鐞嗭紝鏍规嵁鎻愬彇浣嶇疆鐨勪笉鍚岋紝鐩稿簲鐨勫嚱鏁版湁LEFT銆丮ID銆丷IGHT銆俁IGHT鍦鑻辨枃涓渶甯歌鐨勬剰鎬濇槸鈥滃悜鍙炽佸彸杈光濓紝EXCEL涓璕IGHT灏辨槸鏍规嵁鎵鎸囧畾鐨勫瓧绗︽暟杩斿洖鏂囨湰瀛楃涓蹭腑鍙充晶鑻ュ共涓瓧绗︾殑鍑芥暟锛汻IGHT鍑芥暟鏈変袱涓弬鏁帮紝璇硶涓猴細RIGHT(text,[num_chars...
绛旓細涓嬮潰鐨勪唬鐮佸彧鏄鐞嗕腑闂存病鏈夌┖鏍肩殑涓涓插瓧绗锛涜澶勭悊鏈夌┖鏍肩殑鍙渶鎶瀛楃涓A鐨勫垱寤烘敼鎴 瀛楃涓叉暟缁凷tring [] A = new String[30];杈撳叆鍜屽垽鏂氨鐢ㄥ惊鐜悶瀹氥傛垜涔熸槸杩欏鏈熼変慨鐨刯ava锛屾湁浠涔堜笉瓒宠繕璇锋寚姝c俰mport java.util.*;public class tongji { public static void main(String[] args){ String...