#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>
#include<stdio.h>
void main()
{
char a[] = "hello! the weather of Today is Good, and You are so beautiful!";
int count = 0;
if (a[0]<65 || a[0]>65+26 - 1)//改写单词首字母为大写字母
{
a[0] = a[0] - 32;
count++;//记录有多少个单词
}
for (int i = 0; a[i] != '\0'; i++)//遍历字符数组
{
if (a[i] == ' ')
{
if (a[i + 1]<65 || a[i + 1]>65+26 - 1)//改写单词首字母为大写字母
{
a[i + 1] = a[i + 1] - 32;
count++;//记录有多少个单词
}
}
}
for (int i = 0; a[i] != '\0'; i++)//打印结果
{
printf("%c", a[i]);
}
system("pause");
}
有一行字符,统计其中的单词个数(单词之间以空格分隔),并将每一个单词的第一个字母改为大写
最新推荐文章于 2024-10-17 22:53:28 发布