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] = "AB";
char SeatRight[3] = "CD";
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;
}
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] = "AB";
char SeatRight[3] = "CD";
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;
}