Using strings: porting from FreeBasic

Robin2:
Can you have an array of variable length arrays?

...R

Not really... and it surely can be wasteful on resources.
Using Quincy 2005 (free download) on 32-bit Windows, the following code compiles:

#include <stdio.h> 
#include <conio.h> 
#include <iostream>	// std::cout

using namespace std ;

// allocating WORST CASE length ... wasteful for short strings
char myList[][15] = {
    "Dogs drool",
    "Cats rule",
    "Hamsters sleep",
    "Lizards leap"
  };

int main()
{
	cout << "Beginning test run... \n\n\n" ;
	int size = sizeof(myList) ;
	cout << "Size of []:" << size << "\r\n" ;

	for (int i = 0; i < sizeof(myList) / sizeof(myList[0]); i++)
	{
    	cout << i << "= " << myList[i] << "\n\r";
	}

	for (int i = 0; i < sizeof(myList) / sizeof(myList[0]); i++)
	{
    	cout << myList[i] ;
	}

   return 0;
}

and produces this console output:

Beginning test run...

Size of []:60
0= Dogs drool
1= Cats rule
2= Hamsters sleep
3= Lizards leap
Dogs droolCats ruleHamsters sleepLizards leap
Press Enter to return to Quincy...

So the 46+4 nulls (\0) = 50 characters actually took 60 bytes of storage because each line was blocked at 15 characters!

Ray