Printing to a Specific row on an logfile

Hello people,

I need guidance on how to print to the second row of an already existing file. My program goes like this

  1. Check time, Print to an SD card
  2. Do something
  3. Print to an SD Card
  4. Do something again, Print to an SD card.

I want all entries to be on the same row but different columns. But when my program executes logic #3 and #4 it prints on different lines.

Any ideas?

flippomendes:
Any ideas?

Yeah, the problem is your code which we can't see.

Okay... Here is a portion of my code that executes #4

//comparison to see if the present time and the previous time is within a range to warrant a comparison
if (((datePrev == dateNow) && (monthPrev == monthNow) && (yearPrev == yearNow))||((dateNow - datePrev == 1)&& (yearPrev == yearNow)) ||((dateNow ==1)&&(monthNow - monthPrev ==1) && (yearNow == yearPrev)))
{
if (hourNow == 0) // sets the hour value to 24 if the time is at midnight
{
hourNow = 24;
}
int totalTimeMin = ((hourNow * 60) + minutesNow)- ((hourPrev * 60) + minutesPrev); //math to get the time difference
Serial.print(totalTimeMin);
addValues = SD.open(fileSearch, FILE_WRITE); //open the already existing file to append new values
if (!addValues) {
Serial.println("Can't open file");
return;
}

addValues.print(", ");
addValues.print(", ");
addValues.print(", ");
addValues.print(totalTimeMin); //Print totalTimeMin as breakTime
addValues.flush();

If anyone can let me know whether or not this is possible I will appreciate it.

You have to open two files. The first one is the original (source), the second one is a new one (destination).
Copy first line from source to destination, insert new line in destination, copy remaining lines from source to destination.
Close both files and delete the original; rename the new file.

It's the only way.

I want all entries to be on the same row but different columns

How many columns will there be in total ? Will you ever start a new row ?

UKHeliBob:
How many columns will there be in total ? Will you ever start a new row ?

No I will never start a new row. I have 5 columns

If I have got this right you want to print 5 items of data separated by 4 commas all on the same line. Is that right ? If so then can I suggest that you collect the data and when all 5 data items have been collected send them and the commas to the file.