printing out a 2d char array, In C++ it just wacks the hell out of it, and comes up with its own abbreviations for what is in the array, and in C it chops off part of the last word in the first element being printed. NOT using element 0, btw.
What would be a better way to print out various sizes in an array like this?
Code:
#include <iostream>
using namespace std;
int main()
{
char snacks[7] [30] = { " ", "Cracker Jacks","Gummy Bears","Lemon Heads",
"Skittles","Snickers","Milky Way"};
size_t count = 1, col = 0;
for ( ; count < 7 ; count++)
{
for (; col != '\n'; col++)
{
cout <<snacks[count][col];
col++;
}
cout<<endl;
col = 0;
}
//same code compiled in C as well
//gets same output
printf("\ntime two\n"
"C code\n\n");
count = 1, col = 0;
for ( ; count < 7 ; count++)
{
for (; col != '\n'; col++)
{
printf("%c", snacks[count][col]);
}
printf("\n");
col = 0; //reset
}
return 0;
}
Results
Code:
userx@slackwhere:~/bin
$ ./temp
CakrJ
GmyBa
LmnHa
Site
Sikr
MlyWy
time two
C code
Cracker Ja
Gummy Bear
Lemon Head
Skittles
Snickers
Milky Way