Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
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();
}
Posted
Updated 13-Sep-13 8:34am
v3

1 solution

You could just do this:

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


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.
 
Share this answer
 
v2
Comments
CPallini 13-Sep-13 17:34pm    
My 5. The OP code actually declares toupper as a void function returning and int.
Ron Beyer 13-Sep-13 18:41pm    
Thanks, not sure why the downvote (know it wasn't you), seems perfectly legal if you just want to capitalize the first letter of a string.
CPallini 14-Sep-13 2:41am    
I don't understand the downvote too (I gave you 5, of course).
kashiiii 13-Sep-13 20:53pm    
Yeah Working Now Thanks Ron beyer :),i am working with ctype.h & the problem was with int toupper; which i declared
Richard MacCutchan 14-Sep-13 5:32am    
You should not use numbers, especially decimals, in statements such as the above, as it's difficult to know what they represent. Use the actual characters to represent themselves like:

if (str[0] >= 'a' && str[0] <= 'z')
str[0] -= ' ';

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900