Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » allegro GUI

This thread is locked; no one can reply to it. rss feed Print
allegro GUI
chaseC
Member #8,368
February 2007

Hi, I just learned how to use d_edit_proc and was wondering how you convert the user generated string into an int format so that I could use it as a variable????

LennyLen
Member #5,313
December 2004
avatar

chaseC
Member #8,368
February 2007

went I use atoi in the simple program

1#include <allegro.h>
2#include <stdlib.h>
3 
4char edittext[32] = "12345";
5int a;
6 
7int main(int argc, char *argv[]){
8
9 allegro_init();
10 install_keyboard();
11 set_color_depth(24);
12 set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
13
14 a = atoi(edittext[32]);
15 
16 textprint>:(f(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(255, 0, 0), "%d", a);
17 readkey();
18
19 return 0;
20
21}
22END_OF_MAIN();

the compile log says
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c whatever.cpp -o whatever.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

whatever.cpp: In function `int _mangled_main(int, char**)':
whatever.cpp:14: error: invalid conversion from `char' to `const char*'
whatever.cpp:14: error: initializing argument 1 of `int atoi(const char*)'
whatever.cpp:16: warning: `textprintf' is deprecated (declared at C:/Dev-Cpp/include/allegro/alcompat.h:177)

whatever.cpp:16: warning: `textprintf' is deprecated (declared at C:/Dev-Cpp/include/allegro/alcompat.h:177)

make.exe: *** [whatever.o] Error 1

Execution terminated

>:(>:(>:(

Steve Terry
Member #1,989
March 2002
avatar

a = atoi(edittext);

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

chaseC
Member #8,368
February 2007

Thanks, it works now!;D

Matt Smith
Member #783
November 2000

atoi() is ancient and depecated. strtol(edittext, NULL, 10); is the modern version. There is no strong reason to change it in this particular situation, but it's good to be modern.

edit: Actually, there is a good reason to use Allegro's built-in ustrtol() instead. It handles Unicode properly.

Go to: