想要资本化第一个字母串,但函数toupper不工作。不知道为什么? [英] Want To Capitalize 1st Letter Of String,but the function toupper not working.Dont know why ?

查看:71
本文介绍了想要资本化第一个字母串,但函数toupper不工作。不知道为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main()

clrscr();

int toupper();
char str[20]="i am good";
int length,i;

length=strlen(str);
str[0]=toupper(str[0]);  //Error here (Extra Parameter in call to toupper() ??

cout<<str[0];

for(i=1;i<length;i++)>
{
if(str[i]==' ')
str[i+1]=toupper(str [i+1]);   //Here aswell

cout<<str[i];
}
getch();
}

推荐答案

你可以只需这样做:



You could just do this:

if (str[0] >= 97 && str[0] < 173)
    str[0] -= 32;





看一下ascii图表,你会看到它们是如何间隔的。



你的问题是你已经将toupper()定义为整数或其他东西,所以你没有使用stdlib代码,你做了一些奇怪的事情。从字符串正上方删除int toupper()行并查看它是否有效,您没有概述您正在使用的库,因此不确定您是否具有正确的包含。



Take a look at an ascii chart once, you'll see how the are all spaced.

Your problem is that you've defined toupper() as an integer something or other, so you aren't using the stdlib code, you are doing something weird. Remove the int toupper() line from just above the string and see if it works, you didn't outline what libraries you are using so not sure that you have the right includes.


这篇关于想要资本化第一个字母串,但函数toupper不工作。不知道为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆