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

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

#include<stdio.h>
#include<stdlib.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");


}

猜你喜欢

转载自blog.csdn.net/qq_33560272/article/details/86650111