convert to upper
Nov 20, 2011 at 9:02am UTC
have the following:
1 2 3 4
char input;
cin.getline(input);
trying to check if lowercase input, trying to make it become uppercase automatically instead...
but i keeps getting this error
abc.cpp: In function ‘int main(int, char**)’:
abc.cpp:94:8: error: invalid conversion from ‘char*’ to ‘char
i tried alot of combinations including toupper #include <cctype> but stil couldn't get the results i want, any idea why ?
Last edited on Nov 20, 2011 at 9:46am UTC
Nov 20, 2011 at 9:13am UTC
1 2 3 4 5
for (int i = 0 ; i < strlen(input) ; i++)
{
ch = toupper(input[i]);
cout<<(char )ch;
}
Nov 20, 2011 at 9:20am UTC
thanks but still same issue.
anyw i've resolved it already
Last edited on Nov 20, 2011 at 9:46am UTC
Nov 20, 2011 at 10:57am UTC
hi,
your code:
1 2
char input;
cin.getline(input);
cin.getline() function reads chars until '\n' and removes '\n' (also you are missing length as second parameter)
you'll have to use cin.get() OR
change input variable to char [] or string.
then use toupper function to change the fisrt letter, or use for loop to change all chars as bluecoder described.
cheers.
Last edited on Nov 20, 2011 at 11:01am UTC
Nov 24, 2011 at 3:50pm UTC
Original Post:
wantyoubadly wrote:
have the following:
1 2
char input;
cin.getline(input);
trying to check if lowercase input, trying to make it become uppercase automatically instead...
but i keeps getting this error
abc.cpp: In function ‘int main(int, char**)’:
abc.cpp:94:8: error: invalid conversion from ‘char*’ to ‘char
i tried alot of combinations including toupper #include <cctype> but stil couldn't get the results i want, any idea why ?
wantyoubadly has the tendency to remove the original post, so I am preserving it here in the (very likely) event that this happens here too.
Topic archived. No new replies allowed.