您的位置:首页 > 其它

把输入字符的小写转换成大写并输出

2014-03-08 09:25 260 查看
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*******************************
*把小写字母转成大写字母
********************************/
int main(void)
{	
	char *src=NULL;
	unsigned char i=0;
	char *new_1=NULL;
	char *new_2=NULL;
	char *d=NULL;
	src = (char*)malloc(50);
	new_2 = (char*)malloc(50);
	d = (char*)malloc(50);
	printf("****************************************\n");
	gets(src);
	new_1=src;
	i=strlen(src);
//	printf("i:%d\n",i);
	while(i)
	{
		if((*new_1>='a'))
		{
			*d=*new_1-32;
			//printf("%c",*d);
		}
		else
		{
			*d=*new_1;
			//printf("%c",*d);
		}
		i--;
		
		//printf("%c",*new_1);
		//printf("%c",*d);
		new_1++;
		d++;
	}
	*d=0;
	d=d-strlen(src);//让d批针回到字符串首地址
	strcpy(new_2,d);//字符串复制函数
	printf(new_2);
	printf("\n");
	printf("****************************************\n");
	free(src);
	free(new_2);
	free(d);
	return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐