C语言字符数组,定义大写字母字符数组和小写字母字符数组,可以直接拷贝,以后就不需要自己再输入。

C语言字符数组:包含全部大写英文字母和小写英文字母

C语言字符数组:包含全部大写英文字母和小写英文字母

C语言字符数组,定义大写字母字符数组和小写字母字符数组,可以直接拷贝,以后就不需要自己再输入。

源程序

在这里插入代码片
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{
	int i,j;
	char LowLetters[27]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	char CaptialLetters[27]={'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	char letters[27];
	scanf("%s",letters);//整体输入字符数组(字符串) ,以'.'作为结束符 
//	for (i=0;i<=26;i++)
//	{
//		printf("%c  ",LowLetters[i]);//采用循环语句输出字符数组
//	}
//	printf("\n");
//	printf("%s",LowLetters);//整体输出字符数组语句,s是指字符串
//	printf("\n");
//	printf("%s",CaptialLetters);
//	printf("\n");
	printf("%s",letters);//整体输出字符数组 
	for (i=0;i<=26;i++)
	{
		if(letters[i] =='.')
			break;//判断循环中是否遇到结束符:'.' ,如果是,就结束循环语句 
		for(j=0;j<=27;j++)//用英文字母库中的元素和输入的字母进行比较,判断是否相同,以确定输入的是哪个字母 
		{
		
			if (LowLetters[j] == letters[i])
				{
					printf("%d,",j);
					break;
				}
			if (CaptialLetters[j] == letters[i])
				{
					printf("%d,",j);
					break;
				}
		}
	}
	scanf("%s",letters);
	
	return 0;
}```


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 可以使用C语言中的字符函数isupper()和tolower()来判断是否为大写字母和转换为小写字母,然后将小写字母复制到新的字符串中。 下面是一个示例代码: ```c #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char str[100]; printf("请输入一个字符串:"); fgets(str, sizeof(str), stdin); str[strcspn(str, "\n")] = '\0'; // 去掉fgets读入的换行符 char new_str[100]; int j = 0; for (int i = 0; str[i] != '\0'; i++) { if (!isupper(str[i])) { // 如果不是大写字母 new_str[j++] = tolower(str[i]); // 转换为小写字母并复制到新字符串中 } } new_str[j] = '\0'; // 字符串结尾要加上'\0' printf("去除大写字母后的字符串为:%s\n", new_str); return 0; } ``` 输入: ``` 请输入一个字符串:Hello World! 123 ``` 输出: ``` 去除大写字母后的字符串为:ello orld! 123 ``` ### 回答2: 你可以使用C语言中的字符数组和循环结构来实现这个功能。 首先,定义一个字符数组来存储输入的字符串,假设数组名为str。然后,使用scanf函数接收用户的输入,将输入的字符串存储到str中。接下来,使用一个循环从数组中逐个判断字符的ASCII值是否在大写字母的范围内(65-90),若不在,则将该字符添加到一个新的字符数组中,假设为result。最后在循环结束后,输出result即可。 以下是示例代码: ```c #include <stdio.h> int main() { char str[100]; char result[100]; int i, j = 0; // 接收用户输入的字符串 printf("请输入一个字符串:"); scanf("%s", str); // 遍历字符串 for (i = 0; str[i] != '\0'; i++) { // 判断字符是否在大写字母的ASCII范围内 if (str[i] < 65 || str[i] > 90) { // 将字符添加到结果数组中 result[j++] = str[i]; } } // 在结果数组末尾加上字符串结束标志符 result[j] = '\0'; // 输出结果数组 printf("去除大写字母后的字符串为:%s\n", result); return 0; } ``` 当用户输入一个字符串后,程序会将输入的字符串中的大写字母除去,然后输出剩余的字符组成的字符串。 ### 回答3: 要实现将输入的字符串中的大写英文字母除去,输出剩余的字符组成的字符串,可以使用C语言的字符串处理函数和循环来解决。 首先,我们需要使用`scanf`函数获取用户输入的字符串。然后,使用循环逐个检查字符串中的字符。 在每次循环中,我们可以使用`isupper`函数来判断当前字符是否为大写英文字母。如果是大写字母,我们可以使用字符串处理函数`strcpy`将其跳过,不将其拷贝到输出字符串中。 在循环结束后,我们可以使用`puts`函数将输出字符串打印出来,或者将其赋值给一个新的字符数组变量并输出。 下面是一段示例代码: ```c #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char inputString[100]; char outputString[100]; int outputIndex = 0; int i; printf("请输入一个字符串:"); scanf("%s", inputString); for (i = 0; i < strlen(inputString); i++) { if (!isupper(inputString[i])) { outputString[outputIndex] = inputString[i]; outputIndex++; } } outputString[outputIndex] = '\0'; // 添加字符串结束符 printf("剩余的字符组成的字符串为:%s\n", outputString); return 0; } ``` 在这个示例代码中,我们首先定义了两个字符数组,`inputString`用于存储用户输入的字符串,`outputString`用于存储剩余的字符组成的字符串。`outputIndex`是输出字符串的索引,用于记录将要插入输出字符串中的下一个字符的位置。 通过循环遍历输入字符串,不断检查每个字符是否为大写英文字母。如果不是,将其插入到输出字符串中,并更新`outputIndex`索引。循环结束后,给输出字符串末尾加上字符串结束符。 最后,使用`printf`函数将输出字符串打印出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangjincn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值