[ragel-users] How to get a C "int" value? [SOLVED]

Iñaki Baz Castillo ibc at aliax.net
Fri Dec 4 01:13:55 UTC 2009


El Viernes, 4 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> El Viernes, 4 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> > Hi, for sure I miss something very easy...
> >
> >   alphtype unsigned char;
> >   DIGIT    = "0".."9";
> >   position = ( DIGIT )+ >start_position %end_position;
> >
> > I just want to get the 'position' numeric value into a 'position' int C
> > variable, so I try:
> >
> >   int *position_pointer = NULL;
> >   int position;
> >   [...]
> >   action start_position  { position_pointer = p; }
> >   action end_position    { position = *position_pointer; }
> >
> > However, even if the parser works perfectly I get these values when
> >  printing the variable position with "printf("position = %i\n",
> >  position);".
> >
> > This is the mapping I get between the numbers I pass to the parser and
> > the value of obtained "position" C int variable:
> >
> >   1 => 1681204529
> >   2 => 1681204530
> >   3 => 1681204531
> 
> Ok, I understand: what I'm getting from Ragel are chars, not int values.
> I must convert the string representing a integer to a real int variable,
>  but that's out of the Ragel's scope :)

It was easy. I just need to store the pointer where "position" start so get a 
char*, and use atoi(pointer).


-- 
Iñaki Baz Castillo <ibc at aliax.net>




More information about the ragel-users mailing list