Go Down

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

bluebubble

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?

PaulS

Quote
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.

Jimmy60

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



holmes4

A look at this Tutorial would help a great deal.

http://pw1.netcom.com/~tjensen/ptr/pointers.htm

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

http://books.google.co.uk/books?id=4vm2xK3yn34C&pg=PA276&lpg=PA276&dq=iliffe+vector&source=bl&ots=Ho85Rc1K9Z&sig=aoESEU0iMKKULpF0BlJpWuN4lAk&hl=en&sa=X&ei=ZoS2UODvBcmc0QXAioCYDQ&ved=0CG8Q6AEwDA#v=onepage&q=iliffe%20vector&f=false

Mark

bluebubble

#4
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