c语言,输入一组字符串,第一个字母的首字换成大写。然后输出原字符串和换过的字符串 输入一个字符串,统计其中的单词个数,将第一个单词的首字母改为...
c\u8bed\u8a00\uff1a\u8f93\u5165\u4e00\u884c\u82f1\u6587\u5b57\u7b26\u4e32\uff0c\u628a\u6bcf\u4e2a\u5355\u8bcd\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u53d8\u4e3a\u5927\u5199\uff0c\u8f93\u51fa\u4fee\u6539\u540e\u7684\u5b57\u7b26\u4e32#include
#include
#include
int main(int argc,char*argv[])
{
char str[100+1];
int isfirst=1;
char ch;
int i=0;
while((ch=getchar())!=EOF)
{
if(isalpha(ch))
{
if(isfirst==1)
{
ch=toupper(ch);
isfirst=0;
}
}
else
{
isfirst=1;
}
str[i++]=ch;
}
str='\0';
printf("%s\n",str);
return 0;
}
\u6269\u5c55\u8d44\u6599\uff1aprintf\u7528\u6cd5\uff1a
printf()\u51fd\u6570\u7684\u8c03\u7528\u683c\u5f0f\u4e3a:printf("",)\u3002
\u5176\u4e2d\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5305\u62ec\u4e24\u90e8\u5206\u5185\u5bb9\uff1a\u4e00\u90e8\u5206\u662f\u6b63\u5e38\u5b57\u7b26\uff0c\u8fd9\u4e9b\u5b57\u7b26\u5c06\u6309\u539f\u6837\u8f93\u51fa;\u53e6\u4e00\u90e8\u5206\u662f\u683c\u5f0f\u5316\u89c4\u5b9a\u5b57\u7b26\uff0c\u4ee5"%"\u5f00\u59cb\uff0c\u540e\u8ddf\u4e00\u4e2a\u6216\u51e0\u4e2a\u89c4\u5b9a\u5b57\u7b26\uff0c\u7528\u6765\u786e\u5b9a\u8f93\u51fa\u5185\u5bb9\u683c\u5f0f\u3002
\u53c2\u91cf\u8868\u662f\u9700\u8981\u8f93\u51fa\u7684\u4e00\u7cfb\u5217\u53c2\u6570\uff0c\u5176\u4e2a\u6570\u5fc5\u987b\u4e0e\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6240\u8bf4\u660e\u7684\u8f93\u51fa\u53c2\u6570\u4e2a\u6570\u4e00\u6837\u591a,\u5404\u53c2\u6570\u4e4b\u95f4\u7528","\u5206\u5f00,\u4e14\u987a\u5e8f\u4e00\u4e00\u5bf9\u5e94\uff0c\u5426\u5219\u5c06\u4f1a\u51fa\u73b0\u610f\u60f3\u4e0d\u5230\u7684\u9519\u8bef\u3002
\u6bd4\u5982\uff1a
int a=1234\uff1b
printf("a=%d\n",a);
\u8f93\u51fa\u7ed3\u679c\u4e3aa=1234\u3002
scanf()\u662fC\u8bed\u8a00\u4e2d\u7684\u4e00\u4e2a\u8f93\u5165\u51fd\u6570\u3002\u4e0eprintf\u51fd\u6570\u4e00\u6837\uff0c\u90fd\u88ab\u58f0\u660e\u5728\u5934\u6587\u4ef6stdio.h\u91cc\uff0c\u56e0\u6b64\u5728\u4f7f\u7528scanf\u51fd\u6570\u65f6\u8981\u52a0\u4e0a#include\u3002
int scanf(const char*restrict format,...);
\u51fd\u6570scanf()\u662f\u4ece\u6807\u51c6\u8f93\u5165\u6d41stdin(\u6807\u51c6\u8f93\u5165\u8bbe\u5907\uff0c\u4e00\u822c\u6307\u5411\u952e\u76d8)\u4e2d\u8bfb\u5185\u5bb9\u7684\u901a\u7528\u5b50\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u8bf4\u660e\u7684\u683c\u5f0f\u8bfb\u5165\u591a\u4e2a\u5b57\u7b26\uff0c\u5e76\u4fdd\u5b58\u5728\u5bf9\u5e94\u5730\u5740\u7684\u53d8\u91cf\u4e2d\u3002
\u5982\uff1a
scanf("%d%d",&a,&b);
\u51fd\u6570\u8fd4\u56de\u503c\u4e3aint\u578b\uff0c\u5982\u679ca\u548cb\u90fd\u88ab\u6210\u529f\u8bfb\u5165\uff0c\u90a3\u4e48scanf\u7684\u8fd4\u56de\u503c\u5c31\u662f2\u3002
\u626b\u63cf\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\uff0c\u8fde\u7eed\u7684\u5b57\u7b26\u5230\u7a7a\u683c\u7684\u65f6\u5019\uff0c\u5c31\u8868\u793a\u4e00\u4e2a\u5355\u8bcd\u7ed3\u675f\u4e86\uff0c\u518d\u4ece\u4e0b\u4e00\u4e2a\u5b57\u7b26\u5f00\u59cb\uff0c\u9996\u5148\u5ffd\u7565\u6240\u6709\u7684\u7a7a\u683c\u5b57\u7b26\uff0c\u5230\u5b57\u6bcd\u7684\u65f6\u5019\u8ba4\u4e3a\u662f\u65b0\u5355\u8bcd\u7684\u5f00\u59cb\uff0c\u4ece\u6b64\u76f4\u5230\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\uff0c\u6700\u540e\u8f93\u51fa\u5355\u8bcd\u7684\u4e2a\u6570
请看如下代码:
#include <stdio.h>
#include <string.h>
/*
第一个字母的首字换成大写。然后输出原字符串和换过的字符串
*/
int main()
{
/*初始化原始字符串 src*/
char *src = "i am lower chars.";
/*从原始字符串复制一个新的字符串 dest*/
char *dest = new char[strlen(src)+1];
memset(dest, 0, strlen(src) + 1);
strcpy(dest, src);
/*把新字符串dest的首字符转换为大写*/
dest[0] = towupper(dest[0]);
/*输出*/
printf("原来的字符串:%s
", src);
printf("新的字符串:%s
", dest);
getchar();
return 0;
}
我理解你这”第一个字母的首字换成大写“为“每个单词的首字母换成大写”,问题描述不太明白,具体自己再改程序吧!
#include "iostream"
using namespace std;
int main(void)
{
int i = 0;
char * hello = new char[50];
gets(hello);
printf("the source string is:");
puts(hello);
if(hello[0] >= 'a' && hello[0] <= 'z')
hello[0] -= 32;
while(hello[i] != '\0')
{
if(' ' == hello[i] && hello[i+1] >= 'a' && hello[i+1] <= 'z')
hello[i+1] -= 32;
i++;
}
puts(hello);
system("pause");
return 0;
}
#include "stdio.h"
void main()
{ char str[30];
int i;
gets(str);
printf("%s\n",str);
str[0]=str[0]-32;
printf("%s\n",str);
}
这种问题比较基础,建议你去网站找找郝斌讲的C语言视频看看,自己动手做做
取出字符串的第一个字符,用大小写函数转化下就好了。
绛旓細main(void){ char str[1000];printf("璇杈撳叆瀛楃涓锛");gets(str);if(FirstNotRepeatingChar(str)==0)printf("杈撳叆瀛楃涓蹭腑娌℃湁鎵惧埌绗竴涓鍙嚭鐜颁竴娆$殑瀛楃锛乗n");else printf("杈撳叆瀛楃涓蹭腑绗竴涓彧鍑虹幇涓娆$殑瀛楃涓猴細%c\n",FirstNotRepeatingChar(str));system("pause");return 0;} ...
绛旓細include <stdio.h>int main(){ char str1[100],str2[100]; char *p,*p1,*p2; gets(str1); gets(str2); for(p=str1;*p!='\0';p++) { for(p1=p;p2=str2;*p1==*p2;p1++,p2++); if(*p2=='\0') { printf("%d",p-str1); return 0...
绛旓細include<stdio.h> include<string.h> int main (){ char a[1000],b;int i,n; //n涓哄瓧绗︿覆闀垮害锛沬涓虹粨鏋滐紱printf("璇杈撳叆瀛楃涓锛");gets(a);printf("璇疯緭鍏ュ瓧绗︼細");scanf("%s",&b);n=strlen(a);for(i=0;i<n;i++)if(a[i]==b)break;printf("Result is :%d",i);ret...
绛旓細int main (){ char c[10];int i,j;int a;int sum;sum=0;a=0;scanf("%s",c);for(i=0;i<10;i++){ for(j=0;j<10;j++){ if(i!=j){a=(c[i] == c[j]);sum=sum+a;} } if(sum == 0){printf("%c\n",c[i]);return 0;}/*鎵惧埌绗竴涓灏辩粨鏉燂紝鍚﹀垯鏈夊彲鑳...
绛旓細浣杈撳叆5涓瓧绗︾殑瀛楃涓诧紝鐢ㄧ殑瀛楃鏁扮粍闀垮害鑷冲皯鏄6锛屽洜涓哄瓧绗︿覆缁撳熬杩樻湁涓涓'\0'缁撴潫瀛楃涔熼渶瑕佺┖闂翠繚瀛橈紝鍚﹀垯灏变細鏁扮粍婧㈠嚭銆傚悓鏍蜂笅闈㈢殑鏁扮粍c涔熻瀹氫箟鎴愰暱搴︿负11銆
绛旓細for(i=0,i<lenth(string),i=i+2) printf("%c" *(p+i)); 鍏朵腑p鏄寚鍚瀛楃涓鐨勬寚閽堬紝string浠h〃瀛楃涓层 鍡紝搴旇娌¢敊锛
绛旓細gets_s(a);//鎸夌収鎻愮ず锛氬埄鐢瀛楃杈撳叆鍑芥暟杩涜瀛楃涓茶緭鍏骞跺瓨鍒癮鏁扮粍涓 cout << "璇疯緭鍏:";cin >> m;//鎸夌収鎻愮ず锛氳緭鍏ユ寚瀹氬鍒跺厓绱犺捣濮嬪潗鏍 for (i = 0; b[i - 1] != '\0'; i++)//閬嶅巻浠庢寚瀹氬厓绱犲紑濮嬶紝鍒板瓧绗︿覆缁撴潫鍋滄 { b[i] = a[i + m -1 ];//浠巃鏁扮粍绗琺涓厓绱...
绛旓細) break; } n=0; while ( *s2 ) { s2++; n++; if ( n>=m ) break; } while ( *s2 ) { *s1=*s2; s1++; s2++; } s1=0;} void main() { char s1[256],s2[256]; int m;gets(s1); gets(s2); scanf("%d",&m); f(s1,s2,m-1); printf("%s\n",s1);} ...
绛旓細杩欐牱锛歩nclude<stdio.h> include<string.h> 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!")...
绛旓細鍦╯tring.h閲屾湁涓猻trstr鏂规硶鏄敤鏉ユ煡鎵惧瓙瀛楃涓茬殑锛屼絾涓鑸笉鑳界敤杩欎釜鏂规硶锛岄氬父鐨勬柟娉曞氨鏄亣瀹鏈変竴涓瓧绗︿覆s锛岄暱搴︿负a(闀垮害鍙互鐢眘trlen姹傚嚭鎴栬呰嚜宸辩畻锛夛紝瀛愬瓧绗︿覆s1闀垮害涓篵锛岄偅涔堜粠s鐨勭0涓瓧绗﹀紑濮(i)锛屽埌a-b+1涓烘锛岄愪竴鐢╯trncmp姣旇緝s1鏄惁涓巗+i寮濮嬬殑闀垮害涓篵鐨勫瓧绗︾浉绛夛紝濡傛灉鐩哥瓑锛宨灏辨槸...