Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,665 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,164 people online right now. Registration is fast and FREE... Join Now!




changing an interger to a character.

 
Reply to this topicStart new topic

changing an interger to a character.

Quboid
post 1 Sep, 2007 - 03:23 PM
Post #1


New D.I.C Head

*
Joined: 23 Jul, 2007
Posts: 5


My Contributions


Hello all,

I am writing an assignment program where i have to generate Pascal's triangle. My current method is to do it using a matrix. How ever in order to make the matrix look like a real triangle i have to store (write) spaces (" ") to the places in the matrix that doesn't store the numbers( of the triangle). This is where my problem is, to perfom operations with my matrix i need it to be an integer, so how do I store spaces (which are characters) to positions of a matrix that was declared as an integer. keep in mind that i am using xcode c++ tool for mac osx. Thanks alot in advance!!


Qbo.
User is offlineProfile CardPM

Go to the top of the page

Bench
post 1 Sep, 2007 - 04:37 PM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


characters are already integers, they're just represented differently by I/O libraries/functions when assigned to the char type.

CODE

int space = ' ';


- remember single quotes for characters. I'm not sure why you need to store spaces in a matrix of ints - you'll need to cast them to char if you wish them to be represented as spaces still. (Else you'll get the character code for the space character. The code will depend on which character set you use, e.g, EBCDIC, ASCII etc). If your matrix has other integral values which happen to be the same as your space character code, then this will introduce a nasty bug - You might want to rethink your design in another way.

This post has been edited by Bench: 1 Sep, 2007 - 04:50 PM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 1 Sep, 2007 - 11:42 PM
Post #3


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Characters are stored as ASCII Values (which are unsigned integers) but occupy only 1 byte irrespective of processor architecture.

Integers take up 2,4 or 8 bytes on 16/32/64 bit systems.

You need not worry about this when you are typecasting an integer to a character or viceversa, but this is worth remembering.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:47AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month