[En-Nut-Discussion] sscanf bug?

Anton Veldhuizen antonv at hotmail.com
Fri Nov 19 23:12:20 CET 2004


Hi all,

I'm using WinAVR20040720 Combined with Ethernut 3.9.2. When using sscanf as 
follow the first 2 chars of my string gets cut off:

Code:
char buffer[50];
char number[13];
int index;

strcpy(buffer, "CONFIGCONTACTNUMBER 1 123456789123");
status = sscanf(buffer, "CONFIGCONTACTNUMBER %1d %12s", &index, number);

if (status == 2) {
fputs("index:", General.usart0FilePtr);
itoa(index, buffer, 10);
fputs(buffer, General.usart0FilePtr);
fputs("\n", General.usart0FilePtr);
fputs("number:", General.usart0FilePtr);
fputs(number, General.usart0FilePtr);
fputs("\n", General.usart0FilePtr);
}

Result:
index:1
number:3456789123

>From testing the problem seems to be my %1d conversion, I have tried this 
with %u, %x and %i. Still the first 2 letters of my string gets cut off??? 
Could it be that sscanf is interpreting the <index> as "0x01" (which would 
explain 3 chars skipped)? Also I get a truly bizarre result when I use %d 
instead of %1d - the number string is 12 chars long but, made up of entirely 
random chars.

Can someone please clarify wether NutOS uses it's own version of vfscanf() 
or WinAVR's?

Following is my linking section of my modified ethernut 3.9.2 makefile - I 
have only modified the LIBS section according to the WinAVR manual for 
'flt'.  Is this required for NutOS or is NutOS pre-built with the floating 
point libraries for vfscanf anf vfprintf?

PROJ = gsmgenie

#include $(top_srcdir)/app/Makedefs
include Makedefs

SRCS =  $(PROJ).c global.c init.c rtc.c smsengine.c msghandler.c io.c 
utilities.c pc_uart0_rx.c mc45_uart1_rx.c OBJS =  $(SRCS:.c=.o)
LIBS =  $(LIBDIR)/nutinit.o -lnutos -lnutdev -lnutos -lnutcrt
LIBS += -Wl,-u,vfscanf -lscanf_flt -lm
LIBS += -Wl,-u,vfprintf -lprintf_flt -lm
TARG =  $(PROJ).hex $(PROJ).elf $(PROJ).cof

HEXSIZE = avr-size --target=srec $(PROJ).hex
ELFSIZE = avr-size -A $(PROJ).elf

Thanks,
Anton

_________________________________________________________________
Ensure smooth online surfing with MSN Toolbar! 
http://toolbar.msn.co.za?DI=1054&XAPID=2083




More information about the En-Nut-Discussion mailing list