dear friends, I am a beginner in c programming and I have learned the c++, java as well,
In C I have been asked for a question about how to convert lower case string like any name into uppercase,
and i have read a program for it by pointers and I wanna do it by using typecasting and ascii values for characters so if anyone can help me on that.

3 Years
Discussion Span
Last Post by naveen1993

typecasting doesn't work. You use the macro toupper() on each character in the string (use a loop)


char c = 'a';
c = toupper(c); // convert to upper-case
printf("%c\n", c);

If you write a small program to loop through all the char's a..z and A..Z

and take the difference of each matching pair ...

the results may give you a 'heads up' on what you may be seeking ?

for( int c = 'a', c2 = 'A'; c <= 'z'; ++c, ++c2 )
   // printout c, c2 and difference between c and c2

Edited by David W: fixed spelling typo


Also, the toupper() function won't affect non-alpha characters, such as numbers. So, to be succinct:

/* This is pseudo-code. */
posn = 0;
while (!end-of-string)
    string[posn] = toupper(string[posn]);

There are number of means to code the loop including for (int i = 0, j = strlen(string); i < j; i++), etc.

As AD said, typecasting won't work here. You are trying to apply the wrong tool to the job.


With reference to ur query,
char c='b';
char d;
d=toupper(c);//Here it will convert the b letter into B with the help of ASCII values

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.