C语言实现大小写的转换

C语言实现大小写的转换

要求

编写一个程序,可以一直接收键盘字符,
如果是小写字符就输出对应的大写字符,
如果接收的是大写字符,就输出对应的小写字符,
如果是数字不输出。

代码呈上

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main() {
	char a[100];
	int i;
	printf("请随便输入一些字符串\n");
	while (1) {
		gets(a);
		for (i = 0; i < 100; i++) {
			if (a[i] >= 'a'&&a[i] <= 'z') {
				int j = a[i] - 32;
				putchar(j);
		
			}
			if (a[i] >= 'A'&&a[i] <= 'Z') {
				int j = a[i] + 32;
				putchar(j);
				
			}
		}
		printf("\n");
	}
	system("pause");
	return 0;
}

小"tip"

注意两者的转换:
'a’与’A’之间相差32

发布了29 篇原创文章 · 获赞 10 · 访问量 7499

猜你喜欢

转载自blog.csdn.net/qmqm33/article/details/93392320
今日推荐