Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 dim array not sure what is happening

Status
Not open for further replies.

marcon

Programmer
Aug 30, 2001
21
0
0
US
I have a 2 dim array where strcpy puts AB in the left column and CD in the right. It looks like it is working but when I dump the contents of the array I don't get what I want.
I want it to print what you see below.
AB
AB
AB
AB
AB
AB
AB
CD
CD
CD
CD
CD
CD
CD


Any help greatly appreciated!

#include <iostream>
#include <time.h>
#include <string.h>

using namespace std; //introduces namespace std

char table[7][3];
int Row = 7;
int Col = 3;

void generate();

int main( void )
{

generate();
// display(table[7]);

return 0;
}

void generate()
{
char SeatLeft[3] = &quot;AB&quot;;
char SeatRight[3] = &quot;CD&quot;;
char table[7][3];

for(int i = 0; i < Row; i++)
for(int j = 0; j < Col; j++)
if(i==0)
{
strcpy(table[j], SeatLeft);
}
else
{
strcpy(table[j], SeatRight);
}


for(int k = 0; k < Row; k++)
for(int l = 0; l < Col; l++)
cout << table[k] << endl;




}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top