Solved

ASCII

Posted on 2000-02-29
5
337 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 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

23 Experts available now in Live!

Get 1:1 Help Now