I m using sscanf but it always returns 0. My simple code is :
int var1,var2;
char *buf="100";
var1=sscanf(buf,"%d",&var2);
> var1=var2=0;
in the config file I've tried to change default heap size to 0x400 as suggested in numerous forums and docs but the result is always the same : 0.
what is the trick to use this stdio function ?
Olivier
Make sure you #include <stdio.h> . While you are not doing external I/O, other tips in this wiki article may be helpful.
Thanks and regards,
-George
TI C/C++ Compiler Forum ModeratorPlease click Verify Answer on the best reply to your question.The Compiler Wiki answers most common questions.Track an issue with SDOWP. Enter your bug id in the "Find Record ID" box.
Thank you George for this answer but stdio.h is included and I have already read this wiki. I use the 28069 experimenter kit with sys/bios : sscanf return 0 using %d or %s !
But %f works well.
source :
int var1=0;char *buf="123 456 bonjour";int entier=0;float flottant=0;char buffer[20];char str[50];var1=sscanf(buf,"%f %s %d",&flottant,buffer,&entier);sprintf(str,"sprintf(%f/%s/%d)",flottant,buffer,entier);
return : "123.00000//0" var1=1
What's wrong with this code ?
Sorry for the delay ...
MARTIN OlivierWhat's wrong with this code ?
The code has no problems I can see. Are you sure you have allocated enough stack and heap?
Yes, I'm sure stack and heap size are sufficient and I remind you that scanf with %f works very well. it s so strange.... Nobody has reported this issue ?
Thank you very much,
No, it does not look familiar. Are you sure you are using the sscanf that comes from the RTS library? Please generate the linker map file (with the --map_file linker option) and post that here.
It seems that sscanf comes from RTS lib according to the following map-file :
2063.mapFile.txt
but is rts2800_fpu_eh is the correct lib ? (experimenter kit F28069)
I don't know anything about that kit, so I can't say whether that is the correct library.
From the map file, I note your stack is only of size 0x100, which is quite small. Please try increasing it to 0x500.
Also, the stack is at location 0x0, which is scary; it is conceivable that something in the library might mistake that for the NULL pointer, so you might want to consider restricting the M01SARAM to addresses 0x1 - 0x800
These might not be related to the problem, but it would be helpful to rule them out as causes.
I really appreciate your help. You are totally right, the size of the stack and its location were not correct but it still doesn t work.
Thus, I have try an other project (non bios) in opening usb_dev_keyboard and I encounter a new but similar pb :
UARTprintf("hello%d",123);
return : hello8109848
you can find map file below :
http://e2e.ti.com/cfs-file.ashx/__key/CommunityServer-Discussions-Components-Files/343/3730.usb_5F00_dev_5F00_keyboard.txt
UARTprintf is not part of the compiler's run time support library; I can't say much about it.
My guess is that you don't have a prototype for UARTprintf in scope. Are you sure you included the correct header file?
Hi !
I think that the problem came from the types char and int of the Piccolo 28x family.
char and int are 16-bits long
unsigned long is 32bits long
In the code of uartstdio.c [line 983]
case 'c': {
// Get the value from the varargs. ulValue = va_arg(vaArgP, unsigned long); // can't work with a char !
it should be replaced by: char c=va_arg(vaArgP,char); UARTwrite(&c, 1);
// Print out the character. UARTwrite((char *)&ulValue, 1);
...
MARTIN Olivierva_arg(vaArgP,char)
Technically, that is not strictly legal C code. If a char is passed to a variadic function, it is promoted to int or unsigned int, so that code should be:
va_arg(vaArgP,int)
I realize that it makes no difference for C2000, but the code is strictly legal with "int", and therefore more portable.