Potential bug in strdio?

Amigos,

I found something i do not understand, so i will ask the question:

when running this program, the output is as expected

#include <stdio.h>


char  _line1[] = "0-0:1.0.0(190205140804W)";
char *_line2 = "0-0:1.0.0(190205140804W)";

void setup() {
  Serial.begin(115200);
  printf("\nBooting ...\n");
  printf("PF-_line1 = %s \n", _line1);
  Serial.print("SP-_line1 = ");
  Serial.println(_line1);
  printf("PF-_line1 = %s\n", _line1);
  printf("Booting ...\n");
}

void loop() {
  // put your main code here, to run repeatedly:

}

output

11:29:43.653 -> 
11:29:43.653 -> Booting ...
11:29:43.653 -> PF-_line1 = 0-0:1.0.0(190205140804W) 
11:29:43.653 -> SP-_line1 = 0-0:1.0.0(190205140804W)
11:29:43.653 -> PF-_line1 = 0-0:1.0.0(190205140804W)
11:29:43.653 -> Booting ...

when changing the 2nd printf statement from printf(“PF-_line1 = %s \n”, _line1);
to printf("\nPF-_line1 = %s \n", _line1); this is the output. (added a newline in front of text)

11:47:35.643 -> 
11:47:35.643 -> Booting ...
11:47:35.643 -> 
11:47:35.643 -> SP-_line1 = 0-0:1.0.0(190205140804W)
11:47:35.643 -> PF-_line1 = 0-0:1.0.0(190205140804W)
11:47:35.643 -> Booting ...

Note the MISSING 2nd Line

what gives?

Regards,
Rob

That's exactly what I would expect. When you added the newline, what were you hoping would happen?

Bill,
what i would expect is

11:29:43.653 -> 
11:29:43.653 -> Booting ...
11:29:43.653 ->
11:29:43.653 -> PF-_line1 = 0-0:1.0.0(190205140804W) 
11:29:43.653 -> SP-_line1 = 0-0:1.0.0(190205140804W)
11:29:43.653 -> PF-_line1 = 0-0:1.0.0(190205140804W)
11:29:43.653 -> Booting ...

note the newline after the booting... message, that is what i expect.

thanks for your response,

Rob

That is weird, can you post the code that produces the second output?

that would be

#include <stdio.h>

char _line1 = “0-0:1.0.0(190205140804W)”;
char *_line2 = “0-0:1.0.0(190205140804W)”;

void setup() {
Serial.begin(115200);
printf("\nBooting …\n");
printf("\nPF-_line1 = %s \n", _line1);
Serial.print("SP-_line1 = ");
Serial.println(_line1);
printf(“PF-_line1 = %s\n”, _line1);
printf(“Booting …\n”);
}

void loop() {
// put your main code here, to run repeatedly:

}

note the \n before the PF-_line1 =, that is the only diference

regards,
Rob

BTW, Arduino V1.8.8

Which Arduino

Mark

ESP8266 (NodeMCU V3).

but there is no hardware specific stdio library, so i blame the compiler, not the h/w

Rob

Last time I had the need for “printf” I had to include printf.h in order to make it work, dunno if that is related to your problem.

#include <printf.h>

Albeit, unless you really need to use printf I suggest you use Serial.print instead. If you want to print multiple arguments in one line, you could use a macro:

#define PrintTwo(a, b) Serial.print(a); Serial.println(b)

or something like that.

EDIT: Sorry, this answer applies to the arduino and not the NodeMCU. I think… :slight_smile:

Danois90:
you could use a macro:

Or the more sensible thing anno 2019, a(n inline) function.

i may have spoken to soon, i did a search and found a plethora of stdio files related to 8266.