0

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.

5
Contributors
4
Replies
33
Views
3 Years
Discussion Span
Last Post by naveen1993
0

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

Example

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

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

0

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]);
    ++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.

0

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
printf("%c",d);

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.