Pages: [1]   Go Down
Author Topic: 2d array to 1d array conversion  (Read 1060 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody

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

Code:
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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 600
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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.
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 362
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about an approach like this?

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

Then you would refer to them as:

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



Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 49
Posts: 2159
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everybody
i tried the strcpy() function and everything is working correctly now.

Thanks for your help

edit: thanks holmes4 for that tutorial.
« Last Edit: November 28, 2012, 05:01:13 pm by bluebubble » Logged

Pages: [1]   Go Up
Jump to: