关于C语言输入字符串后将首字母变大写~~~ 在C语言中,如何提取出一组字符串的首字母,并且将其变为大写?...
c\u8bed\u8a00,\u8f93\u5165\u4e00\u7ec4\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u7684\u9996\u5b57\u6362\u6210\u5927\u5199\u3002\u7136\u540e\u8f93\u51fa\u539f\u5b57\u7b26\u4e32\u548c\u6362\u8fc7\u7684\u5b57\u7b26\u4e32\u8bf7\u770b\u5982\u4e0b\u4ee3\u7801\uff1a
#include #include /*\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u7684\u9996\u5b57\u6362\u6210\u5927\u5199\u3002\u7136\u540e\u8f93\u51fa\u539f\u5b57\u7b26\u4e32\u548c\u6362\u8fc7\u7684\u5b57\u7b26\u4e32*/int main(){/*\u521d\u59cb\u5316\u539f\u59cb\u5b57\u7b26\u4e32 src*/char *src = "i am lower chars.";/*\u4ece\u539f\u59cb\u5b57\u7b26\u4e32\u590d\u5236\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32 dest*/char *dest = new char[strlen(src)+1];memset(dest, 0, strlen(src) + 1);strcpy(dest, src);/*\u628a\u65b0\u5b57\u7b26\u4e32dest\u7684\u9996\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5199*/dest[0] = towupper(dest[0]);/*\u8f93\u51fa*/printf("\u539f\u6765\u7684\u5b57\u7b26\u4e32\uff1a%s\n", src);printf("\u65b0\u7684\u5b57\u7b26\u4e32\uff1a%s\n", dest);getchar();return 0;}
#include
\u4e2d\u7684\u4e24\u4e2a\u51fd\u6570\uff0c
1.strupr(\u5c0f\u5199\u8f6c\u5927\u5199)
\u548c
2.strlwr(\u5927\u5199\u8f6c\u5c0f\u5199)
\u539f\u578b\uff1aextern
char
*strupr(char
*s);//*strlwr(char
*s)
\u8bf4\u660e\uff1a\u53ea\u8f6c\u6362s\u4e2d\u51fa\u73b0\u7684\u5c0f(\u5927)\u5199\u5b57\u6bcd\uff0c\u4e0d\u6539\u53d8\u5176\u5b83\u5b57\u7b26\u3002\u8fd4\u56de\u6307\u5411s\u7684\u6307\u9488\u3002
\u4e3e\u4f8b:
#include
#include
int
main()
{
char
*s="copywrite
1999-2000
ggv
technologies";
clrscr();
printf("%s",strupr(s));//strlwr(s)
getchar();
return
0;
}
你这段程序好像不是这个功能吧?像是把输入的字符串送到s2里,然后又把s2赋给s1,最后把s1输出。而且最后那段程序,就是把结束符'/0'从s2复制到s1的那部分,太麻烦了,可以很简单的。
小写变大写,只要减32就可以了!
其实可以用字符串函数实现就很方便了。
头文件为<ctype.h>
tolower()
toupper()
相信你能理解
程序好像没有问题。
绛旓細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 <string.h> define MAX_LENGTH 32 int main(){ char str[MAX_LENGTH] = {0};char *pStr = (char*)&str;//1. 灏瀛楃涓computer璧嬬粰涓涓瓧绗︽暟缁 strcpy(str, "computer");//2. 鐒跺悗浠庣涓涓瀛楁瘝寮濮嬮棿闅斿湴杈撳嚭璇ヤ覆 while(*pStr != '\0' ){ printf("%c\n", *pStr);p...
绛旓細鍦C璇█缂栫▼涓紝涓涓父瑙佺殑浠诲姟鏄皢鐢ㄦ埛杈撳叆鐨勪竴琛瀛楃涓涓殑澶у啓瀛楁瘝杞崲涓哄皬鍐欏瓧姣嶃備互涓嬫槸瀹炵幇杩欎竴鍔熻兘鐨勬楠:棣栧厛锛屾墦寮VisualC++6.0寮鍙戠幆澧冿紝鏂板缓涓涓狢婧愮▼搴忛」鐩傚湪绋嬪簭涓紝鎴戜滑闇瑕佸畾涔変袱涓瓧绗﹀彉閲忥紝c1鍜宑2锛岀敤浜庡瓨鍌ㄨ緭鍏ョ殑瀛楃鍜岃浆鍖栧悗鐨勫瓧绗︼紝浠g爜濡備笅锛歝 char c1, c2;鎺ョ潃锛岀敤鎴烽氳繃閿洏...
绛旓細void f(char s[],int n){ if(s[0]>='a'&&s[0]<='z')s[0]-=32;f1(s);//鏁板瓧涓瀛楁瘝锛屽瓧姣嶄笌鏁板瓧闂寸敤涓嬪垝绾(_)闅斿紑 f2(s);} void f1(char s[],int n){ char ch1,ch2;int i=1,k;ch1=s[0],ch2;while(ch2=s[i],s[i]!='\0'){ if((ch1>='0'&&ch1<='9')&&...
绛旓細鍙瀛楃涓查瀛楁瘝锛岀洿鎺ヨ繑鍥為鍦板潃涓嶅氨琛 浜嗭紵杩欎箞楹荤儲 鈥︹nclude<stdio.h>void main (void){ char str[20]; gets(str); printf("%c", str[0]);}
绛旓細int main(){ int indexInp = 0;int indexRes = 0;char input[100] = {0};char result[100] = { 0 };//杈撳叆瀛楃涓 scanf("%s", input);while (input[indexInp] != '\0')//姣忔璇诲彇涓涓瓧绗︼紝鐩村埌瀛楃涓茬粨灏 { //鍒ゆ柇瀛楃鏄惁鍦26涓ぇ鍐瀛楁瘝鑼冨洿涔嬪锛屾槸鍒欎繚瀛樺埌result鏁扮粍涓 if ...
绛旓細include <stdio.h>#include <string.h>int main(){int len,j;char a[100];scanf("%s",a);//鐢变簬涓嶇煡閬撹杈撳叆澶氬皯锛屾墍浠ヤ互瀛楃杈撳叆len=strlen(a);for(int i=1;i<(len-1);i++){printf("%d",a[i]-'0');//鍐嶈浆鍖栨垚鏁板瓧}return 0;} ...
绛旓細瑕佹眰 璁捐涓涓▼搴 鎶婄彮涓婄殑鍚屽鐨勫悕瀛楄緭鍏鍚 鎸夊悕瀛楃殑濮撶殑鎷奸煶 棣栧瓧姣鎺掑垪銆傝闂浣曡璁°傘傝佸笀杩...C璇█鍚嶅瓧鎺掑簭 C璇█闄愬埗杈撳叆涓哄瓧姣 鍐掓场鎺掑簭鎺掑簭 C璇█ 鍐掓场鎺掑簭鎺掑瓧姣 C璇█杈撳叆涓枃 c璇█
绛旓細include "stdio.h"include "conio.h"main(){ char a[]="computer";char *p = (char*)malloc( strlen(a) * 3 + 1 );int i;for(i=0 ;i< strlen(a) ; i++){ (p+i*3) = a[i];(p+i*3+1) = '\%';(p+i*3+2) = 'D';} (p+i*3) = '\0';puts(p);getch...
绛旓細cout << "璇杈撳叆m:";cin >> m;//鎸夌収鎻愮ず锛氳緭鍏ユ寚瀹氬鍒跺厓绱犺捣濮嬪潗鏍 for (i = 0; b[i - 1] != '\0'; i++)//閬嶅巻浠庢寚瀹氬厓绱犲紑濮嬶紝鍒瀛楃涓缁撴潫鍋滄 { b[i] = a[i + m -1 ];//浠巃鏁扮粍绗琺涓厓绱犲紑濮嬩緷娆″鍒剁粰b鏁扮粍 } cout << "绗琺涓鍚庨潰鐨勫瓧绗︿覆涓:" << b << ...