Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASCII

Posted on 2000-02-29
5
Medium Priority
?
356 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
[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
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 15 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

721 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