SPRINTF help??

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPRINTF help??

825 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by deBoogle on Mon Aug 20 13:06:19 MST 2012
Hi guys,

I know there are a few threads on here regarding the sprintf function, but I'm not sure I am getting it!

I want to convert an integer to a string and i seem to remember using sprintf or snprintf to do this so... I include stdio.h
and then as a test:

uint8_t i = 50;
char buffer [20];

sprintf(buffer, "%d", i);

but i get the following error:

make: *** [TEST1.axf] Error 1

I now its probably a schoolboy error, but any help would be appreciated!

BTW, at the moment I am trying to avoid using the printf to UART mod, for two reasons 1) simplifying porting to other devices and 2) i may eventually want to use floats and I read that may not be possible with the printf to uart mod.

thanks in advance.

deBoogle
0 Kudos
8 Replies

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by deBoogle on Wed Aug 22 06:48:01 MST 2012
I didnt see the sticky thread, but i will go hunting.

much appreciate all your input guys.

deBoogle
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Tue Aug 21 12:38:27 MST 2012
Did you try doing a search using the sticky post at the top of the forum?

Using this you'll see that Code Red have an FAQ on Undefined References that covers this specific error.

HTH!
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Aug 21 12:35:20 MST 2012
That's a semihosting problem :)

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bacbhcee.html
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by deBoogle on Tue Aug 21 12:07:28 MST 2012
Hi Frame, Zero,

Yes indeed.


fseek.c:(.text.fseek+0x1c): undefined reference to `__sys_istty'
fseek.c:(.text.fseek+0x3e): undefined reference to `__sys_flen'
collect2: ld returned 1 exit status
make: *** [TEST1.axf] Error 1

i have no idea what this means.  I can only guess I am missing an include (although stdio and stdlib have been included).
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Tue Aug 21 00:53:07 MST 2012

Quote:
OMG :eek:,  a non-standard C library function :eek:


If memory serves me well, itoa ist (most) often implemented as macro, so it's not even a function...


Quote:
So sprintf is huge and itoa non standard; last option: write your own  little integer to string function and add it to your standard library :rolleyes:



That is true, and should be quite simple.

But back to the start:


Quote:
make: *** [TEST1.axf] Error 1


That can't be all of the error message. Was it an "undefined reference" ?
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 20 14:47:01 MST 2012

Quote: deBoogle
I was always warned away from itoa due to it being non-standard C.



OMG :eek:,  a non-standard C library function :eek:

So sprintf is huge and itoa non standard; last option: write your own little integer to string function and add it to your standard library :rolleyes:
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by deBoogle on Mon Aug 20 14:20:31 MST 2012
I was always warned away from itoa due to it being non-standard C.

but thank you for your help.

deBoogle
0 Kudos

710 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 20 13:37:59 MST 2012

Quote:

I want to convert an integer to a string...

So itoa :confused:

Anyway, did you read this?

http://support.code-red-tech.com/CodeRedWiki/redlib_itoa

Sample: http://knowledgebase.nxp.com/showthread.php?t=3263

BTW: Your problem is no the syntax :eek:

Although I prefer
sprintf(&buffer[0], "%d", i);
to show the pointer to the array

sprintf(buffer, "%d", i);
is working also
0 Kudos