S
srktnc
When I run the program, I get a Debug Error saying
"This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information."
I put a cout statement (//cout << "len of cPtr: " << _len << endl;
) in my constructor and see that _len is 3435973837 though my character
pointer has only a few characters. Then I get the usual message as
state above.
Can someone help?
* * * * * * * * * * * * * *
Here is what I am doing:
--------------------------------------
In header file, I have the following 2 private data members along with
constructors:
char* _str;
unsigned _len;
The constructor I am having problem with is
"STRING (const char*)" that converts a null-terminated array to a
string.
-----------------------------------------------
I set private data member values as shown below:
_len=0;
_str=NULL;
My implementation for THAT constructor is as shown below:
STRING::STRING(const char* c)
/* Pre condition: Array passed must be a valid character array */
{
for (int i=0; c!=NULL; i++)
_len++;
//cout << "len of cPtr: " << _len << endl;
if (_len!=0)
{
_str = new char[_len];
for (unsigned i=0; i <_len+1; i++)
_str = c;
}
else
_str = NULL;
}
------------------------------------------
My main file has
#include "MyString.h" // my header file
int main()
{
char *cPtr= "C";
STRING S(cPtr);
cout << "S(cPtr) is " << endl;
S.Display();
return 0;
};
---------------------------------------------------
"This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information."
I put a cout statement (//cout << "len of cPtr: " << _len << endl;
) in my constructor and see that _len is 3435973837 though my character
pointer has only a few characters. Then I get the usual message as
state above.
Can someone help?
* * * * * * * * * * * * * *
Here is what I am doing:
--------------------------------------
In header file, I have the following 2 private data members along with
constructors:
char* _str;
unsigned _len;
The constructor I am having problem with is
"STRING (const char*)" that converts a null-terminated array to a
string.
-----------------------------------------------
I set private data member values as shown below:
_len=0;
_str=NULL;
My implementation for THAT constructor is as shown below:
STRING::STRING(const char* c)
/* Pre condition: Array passed must be a valid character array */
{
for (int i=0; c!=NULL; i++)
_len++;
//cout << "len of cPtr: " << _len << endl;
if (_len!=0)
{
_str = new char[_len];
for (unsigned i=0; i <_len+1; i++)
_str = c;
}
else
_str = NULL;
}
------------------------------------------
My main file has
#include "MyString.h" // my header file
int main()
{
char *cPtr= "C";
STRING S(cPtr);
cout << "S(cPtr) is " << endl;
S.Display();
return 0;
};
---------------------------------------------------