Sscanf replacement for xilinx EDK

Dear All,

Does anyone know of a replacement for the standard C sscanf() function?

I need to use this function, but it takes a huge chunk memory, a little bit like printf(), and my system based on the spartan-3 starter kit board only has 16KB of memory.

Tanks

Jos=E9 Mariano

Reply to
jmariano
Loading thread data ...

With some luck, you can find a smaller implementation. Otherwise you may be able to write your own scanf. It is always a good idea to create smaller implementations of standard C library functions instead of inventing your own library.

--
Reply to nico@nctdevpuntnl (punt=.)
Bedrijven en winkels vindt U op www.adresboekje.nl
Reply to
Nico Coesel

sscanf takes a huge chunk of memory because it does a lot of formatting. If your format statements can be limited to a small subset of the available data conversion types, for example %x or %d, you could reduce the code size considerably. What formats do you really need? Perhaps you could get away with atoi (ascii to integer) instead of using sscanf?

Reply to
Gabor

Here is a simple reduced version of sscanf I wrote years ago. Hope it helps!

// // Reduced version of scanf (%d, %x, %c, %n are supported) // %d dec integer (E.g.: 12) // %x hex integer (E.g.: 0xa0) // %b bin integer (E.g.: b1010100010) // %n hex, de or bin integer (e.g: 12, 0xa0, b1010100010) // %c any character // int rsscanf(const char* str, const char* format, ...) { va_list ap; int value, tmp; int count; int pos; char neg, fmt_code; const char* pf;

va_start(ap, format);

for (pf = format, count = 0; *format != 0 && *str != 0; format++, str+

+) { while (*format == ' ' && *format != 0) format++; if (*format == 0) break;

while (*str == ' ' && *str != 0) str++; if (*str == 0) break;

if (*format == '%') { format++; if (*format == 'n') { if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { fmt_code = 'x'; str += 2; } else if (str[0] == 'b') { fmt_code = 'b'; str++; } else fmt_code = 'd'; } else fmt_code = *format;

switch (fmt_code) { case 'x': case 'X': for (value = 0, pos = 0; *str != 0; str++, pos++) { if ('0'

Reply to
zcsizmadia

Dear All,

Many tanks for your input. You all have been really helpful.

My special tanks to Zoltan. Your function is now working like a charm in my system.

Best Regards,

Jos=E9 Mariano

Reply to
jmariano

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.