Go Down

Topic: 2d array to 1d array conversion (Read 2044 times) previous topic - next topic


Hi everybody

I'm trying to pass the information of a 2d array to a 1d array like this

Code: [Select]

char listbuffer[81];

char list1[81];
char list2[81];
char list3[81];
char list4[81];
char list5[81];

char* liste[5];

void Setupparty()
  liste[0] = list1;
  liste[1] = list2;
  liste[2] = list3;
  liste[3] = list4;
  liste[4] = list5;

void loop()
  liste[0] = SerialtoChararray(); // madeup function
  listbuffer = liste[x];

Everything works fine except that conversion from 2d to 1d array.

Has anybody got an idea on this?


I'm trying to pass the information of a 2d array to a 1d array like this

Which 2D array are you trying to pass to a 1D array?

You have a several arrays of characters and an array of pointers. All the arrays are 1D.

Code: [Select]
  listbuffer = liste[x];
listbuffer is an array. You can't assign a pointer to an array. There is a strcpy() function to copy NULL terminated arrays of chars from one array to another.

Make sure that your made up function ACTUALLY returns a pointer that points to valid data AFTER THE FUNCTION ENDS.
The art of getting good answers lies in asking good questions.


How about an approach like this?

Code: [Select]

struct List{
char list[81];
} liste[5];

Then you would refer to them as:

Code: [Select]
liste[i].list // where i is the desired index


A look at this Tutorial would help a great deal.


You (of course) can have an array of pointers, an illfe vector search for then in this "Expert C Programming: Deep C Secrets" google book. And now a very long link




Nov 28, 2012, 10:56 pm Last Edit: Nov 28, 2012, 11:01 pm by bluebubble Reason: 1
Hey everybody
i tried the strcpy() function and everything is working correctly now.

Thanks for your help

edit: thanks holmes4 for that tutorial.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131