I'm using Visual C++ and
#include <iostream>
using namespace std;
I initialize a pointer to char at compile time with
char *can1[2]={" "} ;
If I try to write to it I get an error that the memory cannot be written
So then I tried getting new memory at runtime with
for (cnta=0; cnta<=2; cnta++)
can1[cnta]= new char[8] ;
This is great but if I output the new memory with cout I see garbage so I then
had the 'bright' idea to initialize the new memory like so
can1[cnta]=" ";
but after I do this I again get the error message, when I try to write to it, that the memory
cannot be written.
I sense that I'm missing something fundamental here.
Why can't I write to the array if I initialize it either at compile time or run time ?
If I don't initialize the new memory then I can overwrite the strings.
Just learning and trying to understand
Thanks for any ideas.
hugh
#include <iostream>
using namespace std;
I initialize a pointer to char at compile time with
char *can1[2]={" "} ;
If I try to write to it I get an error that the memory cannot be written
So then I tried getting new memory at runtime with
for (cnta=0; cnta<=2; cnta++)
can1[cnta]= new char[8] ;
This is great but if I output the new memory with cout I see garbage so I then
had the 'bright' idea to initialize the new memory like so
can1[cnta]=" ";
but after I do this I again get the error message, when I try to write to it, that the memory
cannot be written.
I sense that I'm missing something fundamental here.
Why can't I write to the array if I initialize it either at compile time or run time ?
If I don't initialize the new memory then I can overwrite the strings.
Just learning and trying to understand
Thanks for any ideas.
hugh