/**
 *
 *	just trying to work out various ways to create arrays dynamicaly and mess with them 
 *
 */

#include <iostream>
using namespace std;

int main(void)
{
    //-- Method 1, using new
    int i;
	long mySize;
    cout << "Enter a size:";
    cin >> mySize;

    long * pMySize = new long[mySize];

    for(i=0; i < mySize; ++i){
        pMySize[i] = i*i*i;
    }
    cout << "Address of pMySize is " << pMySize << " or " << &pMySize[0] << "\n";
    for(i=0; i < mySize; ++i){
        cout << "pMySize[" << i << "] = " << pMySize[i] << "\n";
    }
    delete pMySize;

    //-- method 2, using malloc
    long * pArray;
    pArray = (long *)malloc(mySize*sizeof(long));

    for(i=0; i < mySize; ++i){
        pArray[i] = i*i;
    }

    for(short j=0; j < mySize; ++j){
        cout << "pArray[" << j << "] = " << pArray[j] << "\n";
    }

    free(pArray);

    //-- Use new to allocate an array of strings
    int size;
    cout << "Enter # of strings: ";
    cin >> size;
    char ** pString = new char * [size];
    pString[0] = "hi Jeff-1";
    pString[1] = "hi Jeff-2";
    pString[2] = "hi Jeff-3";

    for(i=0; i < size; ++i){
        cout << "pString[" << i << "] = " << pString[i] << "\n";
    }

    //-- Great, now use malloc to do the same thing!
    cout << "Enter # of strings: ";
    cin >> size;
    char ** ppMe;
    ppMe = (char **)malloc(size*10);
    ppMe[0] = "yo mama!";
    ppMe[1] = "huh?";
    ppMe[2] = "ah... I see.";

    for(i=0; i < size; ++i){
        cout << "ppMe[" << i << "] = " << ppMe[i] << "\n";
    }
   

	return 0;
}
