NO

Author Topic: int variable displayed as a ascii-character  (Read 4132 times)

cd

  • Guest
int variable displayed as a ascii-character
« on: June 16, 2007, 03:27:04 AM »
hi everybody,

i've got a problem with a little thing.

Code: [Select]
// the declaration
int a= 32 ;

how do i  get the ascii-character for the number wich is in the variable a? ???

thx

cd

cane

  • Guest
Re: int variable displayed as a ascii-character
« Reply #1 on: June 16, 2007, 10:25:46 AM »
In this case the character to display is a blank space. BTW, keep in mind that there are other ASCII characters which are non-printable, incidentally the range 0-31.

cd

  • Guest
Re: int variable displayed as a ascii-character
« Reply #2 on: June 16, 2007, 11:52:44 AM »
Oh ok didn't knew that. but just in case for another ascii-character like 75
Code: [Select]
int a=75; and i wanna convert that one to an ascii-character is there a winapi function oder a usual library function wich i can use for it ?

and here just another question to it.

when i use a char array with values like that :
Code: [Select]
char *x={ Aa01 , Bb02 } ;

is a array like that :

Code: [Select]
char x[8];

equeal to that :
Code: [Select]
char x[8]={ Aa01, Bb02 }; = =  char x[0]=A , x[1]=a , x[2]=0 , x[3]=1 , x[4]=B , x[5]=b , x[6]=0 , x[7]=2 x[8]='\0';

or are only the first two arrays with the values declared :
Code: [Select]
char x[0]= Aa01 , x[1]= Bb02;

i only wanna knew or get a correction of my thoughts - help is really appreciated - thx.

later
cd
« Last Edit: June 16, 2007, 12:48:06 PM by cd »

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: int variable displayed as a ascii-character
« Reply #3 on: June 18, 2007, 09:10:30 AM »
Oh ok didn't knew that. but just in case for another ascii-character like 75
Code: [Select]
int a=75; and i wanna convert that one to an ascii-character is there a winapi function oder a usual library function wich i can use for it ?
If you want to know which character is stored in a you can print it with
Code: [Select]
printf("%c", a);
[\code]

[quote author=cd link=topic=2206.msg8286#msg8286 date=1181987564]
and here just another question to it.

when i use a char array with values like that :
[code]
char *x={ Aa01 , Bb02 } ;
[/quote]
This code will not create an array.
To create an array you will need something like this:
Code: [Select]
char x[][] = {"Aa01", "Bb02"};
printf("%s\n", x[0]);         //the output should be Aa01
printf("%s\n", x[1]);         //the output should be Bb02

is a array like that :

Code: [Select]
char x[8];

equeal to that :
Code: [Select]
char x[8]={ Aa01, Bb02 }; = =  char x[0]=A , x[1]=a , x[2]=0 , x[3]=1 , x[4]=B , x[5]=b , x[6]=0 , x[7]=2 x[8]='\0';
for this the array-size must be 9, because you have 2 times 4 characters and the endig zero.

if you want to store this kind of text in your array, you need some code like this:
Code: [Select]
char x[9];

strcpy(x, "Aa01");          // this will copy the string "Aa01" to x
strcat(x, "Bb02");          // this will merge the string "Bb02" to the string x
printf("%s\n", x);          // You will get the output Aa01Bb01

I hope this can help you.  ;)

[/code]
best regards
 Alex ;)

cd

  • Guest
Re: int variable displayed as a ascii-character
« Reply #4 on: June 18, 2007, 12:35:52 PM »
you helped me alot. yes, wright my declaration was just a pointer not a character array and many thanks to solve the question with the integer array.i wasn't sure if i have to cast the type of character or just to use the %c in the printf function , thank you very much.