sprinti function malfunction

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
programmer5
Posts: 69
Joined: 28 Jan 2012 06:50
Location: Pakistan
Contact:

sprinti function malfunction

#1 Post by programmer5 » 30 Mar 2017 06:22

Code: Select all

char someBuffer[100];
sprinti(someBuffer, "{digital_outputs %c %c %c %c}",'1','1','1','0');
I expect someBuffer to be {digital_outputs 1 1 1 0}
But result is {digital_outputs 1 1 0x0F Z}

May I know where I'm doing mistake? Or is it compiler bug?

Thank you.

User avatar
danilo.milovic
mikroElektronika team
Posts: 501
Joined: 05 Dec 2016 14:59

Re: sprinti function malfunction

#2 Post by danilo.milovic » 30 Mar 2017 15:19

Hi,

please send whole project folder in .zip archive so I can reproduce the issue.

Regards,

Danilo

paulfjujo
Posts: 1556
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: sprinti function malfunction

#3 Post by paulfjujo » 30 Mar 2017 18:15

programmer5 wrote:

Code: Select all

char someBuffer[100];
sprinti(someBuffer, "{digital_outputs %c %c %c %c}",'1','1','1','0');
I expect someBuffer to be {digital_outputs 1 1 1 0}
But result is {digital_outputs 1 1 0x0F Z}

May I know where I'm doing mistake? Or is it compiler bug?

Thank you.

sprinti need integer as parameters , not ascii=1 byte

try

Code: Select all

sprinti(someBuffer, "{digital_outputs %c %c %c %c}",0x0031,0x0031,0x0031,0x0030);
or maybe

Code: Select all

sprinti(someBuffer, "{digital_outputs %c %c %c %c}",(int)'1',(int)'1',(int)'1',(int)'0');

programmer5
Posts: 69
Joined: 28 Jan 2012 06:50
Location: Pakistan
Contact:

Re: sprinti function malfunction

#4 Post by programmer5 » 03 Apr 2017 14:16

danilo.milovic wrote: please send whole project folder in .zip archive so I can reproduce the issue.
this is complete project,

Code: Select all

void main() {
char someBuffer[100];
uart1_init(230400);
delay_ms(10);
sprinti(someBuffer, "{digital_outputs %c %c %c %c}",'1','1','1','0');
uart1_write_text(someBuffer);
}
Also attached zip file, board is lv18fj, freq=25MHz, there is no baud rate issue, same result at 9600 baud.


By the way, other sprint library routines (sprintl,sprintf) are also buggy.
Attachments
Capture.PNG
Capture.PNG (60.88 KiB) Viewed 2580 times
sprintBug.rar
(42.66 KiB) Downloaded 139 times

programmer5
Posts: 69
Joined: 28 Jan 2012 06:50
Location: Pakistan
Contact:

Re: sprinti function malfunction

#5 Post by programmer5 » 03 Apr 2017 14:22

paulfjujo wrote: try

Code: Select all

sprinti(someBuffer, "{digital_outputs %c %c %c %c}",0x0031,0x0031,0x0031,0x0030);
or maybe

Code: Select all

sprinti(someBuffer, "{digital_outputs %c %c %c %c}",(int)'1',(int)'1',(int)'1',(int)'0');
As per library documentation, sprinti not necessarily prints only integers, it can print anything except long or float types.

User avatar
danilo.milovic
mikroElektronika team
Posts: 501
Joined: 05 Dec 2016 14:59

Re: sprinti function malfunction

#6 Post by danilo.milovic » 04 Apr 2017 14:17

Hi,

I've just tested

Code: Select all

sprinti(someBuffer, "{digital_outputs %c %c %c %c}",(int)'1',(int)'1',(int)'1',(int)'0');
and it works.

@paulfjujo thanks for helping our users.

Regards,

Danilo

Post Reply

Return to “mikroC PRO for PIC General”