allegro GUI
chaseC

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
chaseC

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

a = atoi(edittext);

chaseC

Thanks, it works now!;D

Matt Smith

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.

Thread #590810. Printed from Allegro.cc