Solved

ASCII

Posted on 2000-02-29
5
338 Views
Last Modified: 2010-04-02
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
Comment
Question by:Barath122599
5 Comments
 

Expert Comment

by:wytze
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

by:
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

by:Barath122599
ID: 2572593
Thank you very much
0
 

Expert Comment

by:Babyworship
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

by:nietod
ID: 3911022
I don't understand.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 how to clear a vector as well as how to detect empty vectors in C++.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now