1. ## stupid question???

how would i convert an int to a char ??

say weve got year, month, day as integers 2 digits long
ie 011114, held as a long int, or 3 separate ints

i want to save the date as a character string

this ought to be easy, but i'm struggling
am i as thick as a elephant sandwich ????

2. In the case of 3 separate ints.
One way is to use sprintf() in <stdio.h>.
For example:
Code:
```   int mon = 11;
int day = 14;
int year = 2001;
char date[11];

printf("%s\n",date);
printf("%s\n",date);```
>am i as thick as a elephant sandwich ????
hehe

3. ## oh yeah !!!! thanx

thanx
thats a good way to do it !!!

4. I use long's

ie lDate=15112001;

I have macros
Code:
```#define		GETDAY(lDate)		(lDate / 1000000)
#define		GETMONTH(lDate)		((lDate / 10000) % 100)
#define		GETYEAR(lDate)		(lDate % 10000)```
Combine this and Swoopies use of sprintf and you may have something.

(sprintf(sDate,"%d/%d/%d",GETDAY(lDate), ect)

5. thats a neat solution, i like that thanx !!!

6. Actually, you cannot convert an int to a char. Even using itoa() or another function doesn't do this.

A char has 8-bits. It may contain an absolute value of 0-255.
An int (usually a short int) has 16-bits. It may contain an absolute value of 0-65535.

When you "convert" a 16-bit int to an 8-bit char, by default you are saying that your int will not be used for any number larger than 0-255 (or -127 to +127). If you try to use a number that is larger than these, when you do the conversion, the top 8-bits are stripped off.

In c, this is represented this way, and may converted to a macro as an exercise to the reader--

int a;
char b;

a = 5;
b = 0;

b = (char)(0x00FF & a);

------
where:

(char) coerces the resultant math to a form compatible with 'b'.
0x00FF is a mask to strip off the top 8-bits.

b == 5

-------

Let's say you have made 'a' larger than 255. What happens? Watch...

a = 27084 ; /* in hex that is: 0x680A */
b = 0;

b = (char)(0x00FF & a);

The stripping:

0x00FF &
0x680A
-------------
0x000A

b == 10 /* or 10 = 0x0A */

-----------------------------------------
enjoy.

7. ## Correction

Typo (for crying out loud I fat fingered the above)--

27084 = 0110 1001 1100 1100 in binary.
hex = 0x69CC

So the logic is:

0x00FF &
0x69CC
----------
0x00CC

b = 0xCC.
b = 204 decimal.

---

Sorry about that, I try to be accurate.

8. Theoretically, C does not recognize characters. Only ints that can be displayed as chars. For instance (don't quote me on the number -- I'm not sure if '40' is 'a'):
Code:
```int letter = 40;   /* don't quote me on the char 'a' */

printf("The letter is %c\n", letter);```
If 40 is == to 'a', then it will print out 'a', not an integer. To do a string, you can just loop through the whole string using this format.

--Garfield

9. right, thanx guys, i'm much the wiser now !!!
learning all the time...............

10. ## to conver #1 to ASCII 1

/*this function works for #0 - 9 it will take a one digit # and convert it to ascii value*/
char int_to_ascii(int x)
{
char char_val ;
char_val = x | 0x0048 ; /* 48 is the ascii value of zero */
return char_val;
}