其他分享
首页 > 其他分享> > C语言用toupper()函数将字符串中的小写字母转化为大写字母;

C语言用toupper()函数将字符串中的小写字母转化为大写字母;

作者:互联网

toupper();函数要包含头文件:
#include <ctype.h>

#include<stdio.h>
#include<ctype.h>
main()
{
	/*
	char str[50] = "hellow world";     很多人开始都这样认为,这样其实是错误的
	str = toupper(str);
	*/
	
	//下面是正确的用法
	int changdu = sizeof(str);	//定义一个变量存储字符串的长度。sizeof()函数涌来计算字符串的长度。
	int i ;						//循环变量
	for(i = 0;i<changdu;i++)
	{
		str[i] = toupper(str[i]);	//将字符串中第 i + 1个元素变成大写的,因为0是第一个元素
	}
	puts(str);
	system("pause");


}

标签:toupper,小写字母,C语言,int,str,字符串,sizeof,include
来源: https://blog.csdn.net/qq_33560272/article/details/86650111