| View previous topic :: View next topic |
| Author |
Message |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Mon May 14, 2007 12:54 pm Post subject: From char to int? |
|
|
I'm not sure I have to convert char to int but heres my problem:
I'm trying to compile this code
| Code: |
// other code up here...
char XCOORD[1024];
char YCOORD[1024];
GetDlgItemText (Hwnd,IDC_XC, XCOORD, 1024);
GetDlgItemText (Hwnd,IDC_YC, YCOORD, 1024);
TextOut(Screen, XCOORD, YCOORD, mytextbuffer, lstrlen(mytextbuffer)); |
unfortunately I get this error: | Quote: | | 'TextOutA' : cannot convert parameter 2 from 'char [1024]' to 'int' |
After looking for TextOut on MSDN, TextOut syntax is | Code: | BOOL TextOut(
HDC hdc, // handle to DC
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // character string
int cbString // number of characters
); |
The X and Y are in "int" therefor my char buffer doesn't work.
Can you guys help me fix this problem?
EDIT: tried atoi(&XCOORD); and reinterpret_cast with no success
_________________
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon May 14, 2007 1:21 pm Post subject: |
|
|
You have to use atoi() on each item in the array individually. Then add them all together while multiplying each number by a power of 10 to keep it in its correct spot. Optimize it yourself, I also haven't tested it so there is bound to be errors.
Edit: Cut the code, after I went over it I decided it was too ugly to let out into the world.
Last edited by Flyte on Mon May 14, 2007 4:03 pm; edited 1 time in total |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon May 14, 2007 2:25 pm Post subject: |
|
|
Are XCOORD & YCOORD ever going to contain a character? (I dont see why co-ordinates would)
If not, just make them integers.
|
|
| Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Mon May 14, 2007 2:36 pm Post subject: |
|
|
Thanks for your answer Flyte. Noz thanks, your right they won't contain any characters
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon May 14, 2007 3:22 pm Post subject: |
|
|
I suppose if you really want them to be char's try:
| Code: |
TextOut(Screen, (int)XCOORD, (int)YCOORD, mytextbuffer, lstrlen(mytextbuffer)); |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon May 14, 2007 4:06 pm Post subject: |
|
|
| noz3001 wrote: | I suppose if you really want them to be char's try:
| Code: |
TextOut(Screen, (int)XCOORD, (int)YCOORD, mytextbuffer, lstrlen(mytextbuffer)); |
|
That would just give the ascii value of the number, not the number itself.
For example:
1 in ascii is 49.
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon May 14, 2007 4:56 pm Post subject: |
|
|
| IF YOU ARE USING A LOT OF REINTERPRET CASTS YOU ARE DOING SOMETHING WRONG
|
|
| Back to top |
|
 |
|