Solved

# ASCII

Posted on 2000-02-29
344 Views
toupper()
Prototype: int toupper(int aChar);
Header File: ctype.h and stdlib.h
Explanation: toupper accepts a character as an argument (it actually accepts an integer, but the two are interchangeable) and will convert it to uppercase, and will return the uppercase character, in the form of an ASCII integer, and leave the parameter unchanged.
Example:
//Program creates char d, sets it equal to lowercase letter
//Converts it to uppercase and outputs it
#include <ctype.h>
#include <iostream.h>

int main()
{
char d;
cin>>d;
d=toupper(d);
cout<<d;
return 0;
}

1) From the above function, int toupper(int aChar). My understanding is it takes only int value only
but from the explaination, it can take char and integer value. Would somebody pls explain!
When I key in "a" , it will output" A". Howver when I key in integer value which is equavalent to small
alphabet a , 97 or hex value 61. This programs output shows  9 for integer value and 6 for hex value.
Why it didnt appear capital "A"
0
Question by:Barath122599
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

Expert Comment

ID: 2569346
replace

char d;

with

int d;

You are not putting the value 97 in the char d but the '9'. There is no upper case for '9'. When you replace the char with int you are putting the value of a char 'a' which is 97 in the variable d and this will convert to 'A'
0

LVL 22

Accepted Solution

nietod earned 5 total points
ID: 2569535
Computers use numbers to represent characters.  The ASCII code is a code that tells what number cooresponds to what letter, like 0 is 'a', 1 is 'b', 2 is 'c', etc.  (The real ASCII code uses different numbers.)

The data type "char" is simply a numeric type.  it is usually an 8 bit type.  That is, it holds values from 0 to 255 or perhaps from -128 to +127.

Since int is also a numeric type if can be used to store characters just as well as char.  The only difference is that it has a larger range of values, so some values of an int doesn't have a meaning as a character.

Why pass an int instead of a char?  Well on some computers it is faster and easier to pass int instead of character, because of the way the CPU works.
0

Author Comment

ID: 2572593
Thank you very much
0

Expert Comment

ID: 3868040
Sorry.

Since 97 is an acceptible number for char type variable.
So,why char d only receive 9 ? not 97?

Thanks
0

LVL 22

Expert Comment

ID: 3911022
I don't understand.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
###### Suggested Courses
Course of the Month4 days, 21 hours left to enroll

#### 738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.