Hi people, I've that code.. when I do debbuging the code's Ok but message error starts up and shows me additional error:debbug assertion failed...when I remove the destructors the error disappear but the output does't show right results...
This programme is for counting dots of some string...
here's code:
#include<iostream>
#include<cstring>
#include<string>
using std::cout;
class mojetrida
{
private:
char *podretezec;
char *ps;
int citac,i,p;
int kraska;
public:
mojetrida();//,int citac,int p);
~mojetrida();
void udelej();
};
mojetrida::mojetrida()//,int citac,int p)
{
podretezec="deb.i.ll.ek";
kraska=strlen(podretezec);
podretezec=new char[];
ps=new char[kraska];
citac, p=0;
};
mojetrida::~mojetrida()
{
delete []podretezec;
delete []ps;
};
void mojetrida::udelej()
{
using std::cerr;
//int citac=0;
//int p=0;
ps=podretezec;
int krasa=strlen(ps);
for(i=0;i<krasa;i++)
{
if (ps[i]=='.')
{
++citac;
}
else if (ps[i]!='.')
{
break;
};
};
cerr<<"vystup je"<<ps<<citac;
};
int main()
{
using namespace std;
cout<<"zadejte retezec";
mojetrida obj=mojetrida();
obj.udelej();
return 0;
}
You should only call delete[] if you allocated your pointer using new;
1 2 3 4 5 6 7 8
mojetrida::mojetrida()
{
podretezec="deb.i.ll.ek"; // You should not delete[] this, you didn't allocate it using new
kraska=strlen(podretezec);
podretezec=newchar[]; // what is this for?
ps=newchar[kraska];
citac, p=0;
};