`
kennethf6986
  • 浏览: 68391 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

面试题目之字符串处理【把字符中的小写字母专为大写】

阅读更多
#include "stdio.h"
#include "conio.h"
#include "string.h"

void main()
{
	void upcase(char *cr, char *us);

	char ss[20];
	char uus[20];

	printf("Please input a String:\n");
	scanf("%s",ss);
	
	upcase(ss,uus);
	
	printf("转为大写为:%s",uus);
}

void upcase(char *cr, char *us)
{
	for(; *cr!='\0'; cr++, us++ )
	{
		if(*cr>='a' && *cr<='z')
		{
			*us = *cr - 32;
		}else
		{
			*us = *cr;
		}
	}
	*us = '\0';
}


这个方法有待于改进,如果输入的字符中有空格的话,就只会输出前一部分。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics