Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sprintf does not compile, printf does not work
01-07-2016, 02:47 PM, (This post was last modified: 01-07-2016, 02:51 PM by Hershell.)
#1
sprintf does not compile, printf does not work
Hey
Consider the following code (v11 PIC18F4550 v4.0)
Code:
int num = 100;

void setup()
{
    pinMode(USERLED, OUTPUT);   
    Serial.begin(4800);
}

void loop()
{
   char tmp[64];
   sprintf(tmp,"i=%i",num);
   Serial.print(tmp);
   // Serial.printf("i = %i\n", num);
   delay(500);
    toggle(USERLED);    // alternate ON and OFF
   num++;
}
The sprintf line does not compile and the printf (commented out prints only "i=". What's wrong?
Reply
01-07-2016, 05:57 PM,
#2
RE: sprintf does not compile, printf does not work
You have to write 
   Sprintf(tmp,"i=%i",num);
instead of
   sprintf(tmp,"i=%i",num);

Look into p8\pdl\pinguino.pdl file line 26
Sprintf psprintf#include <stdio.c>

that means Sprintf (....) is replaced by psprintf(....), defined in stdio.c ,located in p8\include\pinguino\core.

André
PS :if you use version 12 it is true too but the replacement of Sprintf may be different.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)