In my class, I've got - inter alia - a pointer:
Class GSM
{
//...
private:
char *Pin;
//...
}
My constructor initialize it as:
GSM::GSM()
{
//...
Pin = NULL;
//...
}
Now, I want to set default value ("1234") to my PIN. I tried very simple way:
bool GSM::setDefaultValue()
{
lock();
Pin = "0";
for (uint8 i =0; i < 4; ++i)
{
Pin[i] = i+1;
}
unlock();
return true;
}
But it didn't work. When I run my program (I use Visual Studio 2010) there is an error:
Access violation writing location 0x005011d8
I tried to remove line
Pin = "0";
But it didn't help. I have to initialize it as NULL in constructor. It's part of a larger project, but I think, the code above is what makes me trouble. I'm still pretty new in C++/OOP and sometimes I still get confused by pointers.
What should I do to improve my code and the way I think?
EDIT: As requested, I have to add that I can't use std::string. I'm trainee at company, project is pretty big (like thousands of files) and I did not see any std here and I'm not allowed to use it.