I have a 2d char array of 10 rows * 10 columns, which I would like to put into a 1d char array. I need to display 10 rows, some of them will have less than 10 characters but not more than 10.
I have tried memcpy and memmove, but as some of the rows have less than 10 characters, it doesn't really work as they only seem to append a string right after the previous string ends, and cannot contain "empty" characters. I'm not sure if there is any way around this. I have also tried strcat, but I need a way of keeping track of where in the new array I am putting stuff in.
Not sure if code is useful in this instance as this is a more general question about how to handle char arrays.
buf[10][11] = {{'\0'}};
tmpbuf[110] = {'\0'};
int i = 0;
int n = 0;
// something is put into buf
while(something) {
memcpy(tmpbuf + i, buf[n], strlen(buf[n]));
i += 11;
n++;
}
But that only works if each buf actually has 11 chars, doesn't it? The problem is that some bufs will have less than 11 chars, and I suspect there is no way of putting several null chars in an array and then putting chars into it afterwards?