Int to char*...

I am having some problems at conversing formats.

I have a function(getFecha()) (non created by me but I have to use it) which returns timestamp in char*. This is the format:

year, month, date, day, hour, minute, second

09:10:20:03:17:35:00

And I want to upload seconds.

I tried something like this:

USB.print("Time: ");
  USB.println(RTC.getFecha()); 
  char* fecha = RTC.getFecha();
  fecha[19] = '9'; //Seconds (units)
  USB.println(fecha);
  delay(1000);

This works fine. But I want to operate with seconds, in order to upload exactly what I need. If I try: fecha[19] = 9; It fails and fecha[19] = (char) 9; also fails.

Is there anything more before admit that number? If I print fecha (complete sentence) after update number, is fails. It shows this:
09:10:20:03:17:35:0.
So writes a "." I understand...

Any idea?

Hello, try:

fecha[19] = 9 + '0';

It works!! Why this happends? Do you know?

Anyway, thank you so much.

You want to store an ASCII character, the character '0' = 48 in the ASCII table (and the character '9' = 57), so to make the digit 9 into the character '9', you simply add '0' (or 48) to it :). Of course, it's exactly the same for other digits, just add '0' to them.

  char* fecha = RTC.getFecha();

Does getFecha() actually dynamically allocate memory so that it can properly return a pointer? If so, you should be freeing it when you are done.

If not, the function is WRONG! No matter what it is doing.

guix:
Hello, try:

What's the difference between this:

fecha[19] = 9 + '0';

... and this?

fecha[19] = '9';

The former allows you to use a variable instead of the 9, the latter won't.

i.e., this won't work:

int this_is_a_variable = 9;
fecha[19] = 'this_is_a_variable';