Problems with sscanf function

1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello AVR-Freaks,

for a long time, I was using a simple function on an ATmega128 (without external SRAM), which gets an integer out of a string. It made no problems. It looks like this:

int get_int_from_string(char *lpc) { // old (standard) function unsing library    
   int number=-1; 
   sscanf(lpc, "%d", &number); // now d instead of i 
   return number; 


Afer making some changes in the program (but not at this function) and installing the latest WinAvr 20040404, I noticed that always when this function was called the program crashed. :shock:

To get sure that it has to do with this function, I substituted the function above by the following code:

int get_int_from_string_msk(char *lpc) { 

   // 2004-04-16:   Skotti's Integer-Scanner 
   // Attention:    there's no range check! 
   // => input number must be between -32768 and 32767 
   int     number = 0; 
   sbyte factor = 1; // sbyte is defined as signed char 
   if ( (*lpc) == '-' ) { 
   while ( ((*lpc) >= '0') && ((*lpc) <= '9' ) ) {       
      number = number*10 + ((*lpc)-'0'); 
   return (factor * number); 

With the last function the program doesn't crash anymore. :lol:

Now my question(s):
- Do I have to set special options in the makefile for using the sscanf function which were set in older versions of WinAVR by default?
- Or is it just because the sscanf functions needs more stack space than my function (and it has nothing to do with the new version of avr-gcc) ?
- Is there a difference between using %d and %i in the sscanf function?

:idea: Maybe somebody has a clue, how to solve this. Since I know how to work around, it is not urgently, but perhaps someone had (or solved) a similar problem...

Thank you very much. :D

Michael (a.k.a. Skotti)

In the beginning was the Word, and the Word was with God, and the Word was God.