sprintf with more than one value

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
bw64
Posts: 22
Joined: 01 Dec 2011 22:54

sprintf with more than one value

#1 Post by bw64 » 12 Apr 2012 05:53

Hi,
is sprintf with more than one value supported? the following call seems to hang the microcontroller:

int i, j;
char buffer[128];
sprintf(buffer, "message: %d, %d", i, j);

molto999
Posts: 4
Joined: 27 Aug 2011 21:29

Re: sprintf with more than one value

#2 Post by molto999 » 17 Apr 2012 15:31

Hello,

Just Try this:

Code: Select all

int i, j;
char buffer[128];

sprintf("%s message: %d, %d", buffer, i, j);
... and make sure that the string 'buffer' is null terminated...

:mrgreen: regards!

bw64
Posts: 22
Joined: 01 Dec 2011 22:54

Re: sprintf with more than one value

#3 Post by bw64 » 20 Apr 2012 04:37

Hi,

according to the doc...

Code: Select all

void sprintf(char *wh, const code char *f,...);
where...

Code: Select all

wh: destination string 
f: format string 
your example has the destination and format strings in the opposite order... is that how is this library in mikroC supposed to work???

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: sprintf with more than one value

#4 Post by janko.kaljevic » 20 Apr 2012 09:33

Hello,
bw64 wrote:Hi,
is sprintf with more than one value supported? the following call seems to hang the microcontroller:

int i, j;
char buffer[128];
sprintf(buffer, "message: %d, %d", i, j);
I have successfully tested your code and it works like it should.
I used mikroC PRO for PIC2.40 and LV32MX v6 with PIC32MX460.

There is a sprintf example included in compiler, and you can test it.

Best regards.

Post Reply

Return to “mikroC PRO for PIC32 General”