user-0 提问: 大小写转换+后移一位

回复:
user: user-1
content: char chArray[500] = {0}; 	printf("请输入一串数据："); 	int nlen = scanf_s("%s", chArray, 500);  	for(int i=0; chArray[i] != '\0'; i++) 	{ 		if (chArray[i]  >= 'a' && chArray[i] <= 'z') 		{ 			chArray[i] = 'A' + chArray[i] - 'a' + 1; 		} 		else if (chArray[i]  >= 'A' && chArray[i] <= 'Z') 		{ 			chArray[i] = 'a' + chArray[i] - 'A' + 1; 		} 	}  	printf("\n%s\n", chArray);

user: user-2
content: void crypt_char(char *str) {     int i = 0;      while (str[i]) {         if (isupper(str[i]))             str[i] = (str[i] + 1 - 'A') % 26 + 'a';         else if (islower(str[i]))             str[i] = (str[i] + 1 - 'a') % 26 + 'A';         i++;     } }  供参考～

user: user-2
content: void crypt_char(char *str) {     int i = 0;      while (str[i]) {         if (isupper(str[i]))             str[i] = (str[i] + 1 - 'A') % 26 + 32 + 'A';         if (islower(str[i]))             str[i] = (str[i] + 1 - 'a') % 26 - 32 + 'a';         i++;     } }  供参考～

user: user-3
content: 引用 6 楼 lirg8405的回复:或者用gets_s(chArray, 500);代替 谢大佬

user: user-1
content: 或者用gets_s(chArray, 500);代替

user: user-1
content: 引用 4 楼 user-3 的回复:[quote=引用 3 楼 lirg8405的回复:]是的，修改一下  char chArray[500] = {0}; 	printf("请输入一串数据："); 	int nlen = scanf_s("%s", chArray, 500);  	for(int i=0; chArray[i] != '\0'; i++) 	{ 		if (chArray[i]  >= 'a' && chArray[i] < 'z') 		{ 			chArray[i] = 'A' + chArray[i] - 'a' + 1; 		} 		else if (chArray[i]  >= 'A' && chArray[i] < 'Z') 		{ 			chArray[i] = 'a' + chArray[i] - 'A' + 1; 		} 		else if (chArray[i] == 'z') 		{ 			chArray[i] = 'A'; 		} 		else if (chArray[i] == 'Z') 		{ 			chArray[i] = 'a'; 		} 	}  	printf("\n%s\n", chArray);  大佬，我刚学c＋＋还不会c，请问如果用c＋＋ 在for循环里判断是否为空格那个地方怎么写呀， 就是charray[i]！=‘0’这一句[/quote]  改这个：scanf_s("%[^\n]", chArray, 500);

user: user-3
content: 引用 3 楼 lirg8405的回复:是的，修改一下  char chArray[500] = {0}; 	printf("请输入一串数据："); 	int nlen = scanf_s("%s", chArray, 500);  	for(int i=0; chArray[i] != '\0'; i++) 	{ 		if (chArray[i]  >= 'a' && chArray[i] < 'z') 		{ 			chArray[i] = 'A' + chArray[i] - 'a' + 1; 		} 		else if (chArray[i]  >= 'A' && chArray[i] < 'Z') 		{ 			chArray[i] = 'a' + chArray[i] - 'A' + 1; 		} 		else if (chArray[i] == 'z') 		{ 			chArray[i] = 'A'; 		} 		else if (chArray[i] == 'Z') 		{ 			chArray[i] = 'a'; 		} 	}  	printf("\n%s\n", chArray);  大佬，我刚学c＋＋还不会c，请问如果用c＋＋ 在for循环里判断是否为空格那个地方怎么写呀， 就是charray[i]！=‘0’这一句

user: user-1
content: 是的，修改一下  char chArray[500] = {0}; 	printf("请输入一串数据："); 	int nlen = scanf_s("%s", chArray, 500);  	for(int i=0; chArray[i] != '\0'; i++) 	{ 		if (chArray[i]  >= 'a' && chArray[i] < 'z') 		{ 			chArray[i] = 'A' + chArray[i] - 'a' + 1; 		} 		else if (chArray[i]  >= 'A' && chArray[i] < 'Z') 		{ 			chArray[i] = 'a' + chArray[i] - 'A' + 1; 		} 		else if (chArray[i] == 'z') 		{ 			chArray[i] = 'A'; 		} 		else if (chArray[i] == 'Z') 		{ 			chArray[i] = 'a'; 		} 	}  	printf("\n%s\n", chArray);

user: user-3
content: 引用 1 楼 lirg8405的回复:     char chArray[500] = {0}; 	printf("请输入一串数据："); 	int nlen = scanf_s("%s", chArray, 500);  	for(int i=0; chArray[i] != '\0'; i++) 	{ 		if (chArray[i]  >= 'a' && chArray[i] <= 'z') 		{ 			chArray[i] = 'A' + chArray[i] - 'a' + 1; 		} 		else if (chArray[i]  >= 'A' && chArray[i] <= 'Z') 		{ 			chArray[i] = 'a' + chArray[i] - 'A' + 1; 		} 	}  	printf("\n%s\n", chArray);  这个题还有两种特殊情况 输入z或者Z，不能套用if，此时要输出为A和a