Epyon
Well-known member
Okay, I've got this weird problem with passing a pointer and an integer to a function. I have a char array containing a filename and I want to edit this filename every other day. The filename also contains an ID which has to be changed. This is my code.
When I serial print the resulting filename, it gives me gibberish. When I don't edit positions 9 and 10, everything works fine. If I declare an integer 'id' with a value in the function, everything works fine too. Using itoa on id doesn't work.
Am I missing something on passing variables to functions here?
Code:
void getFilename(char *filename, int id) {
int yeari = year(); int monthi = month(); int dayi = day();
char yBuf[4];
itoa(yeari, yBuf, 10);
filename[0] = yBuf[0];
filename[1] = yBuf[1];
filename[2] = yBuf[2];
filename[3] = yBuf[3];
filename[4] = monthi/10 + '0';
filename[5] = monthi%10 + '0';
filename[6] = dayi/10 + '0';
filename[7] = dayi%10 + '0';
filename[8] = '_';
filename[9] = id%10 + '0';
filename[10] = id/10 + '0';
filename[11] = '.';
filename[12] = 'c';
filename[13] = 's';
filename[14] = 'v';
return;
}
Am I missing something on passing variables to functions here?
Last edited: