Why is the following program stuck in a following loop after "Done!", and then ends with a crash?
#include <iostream>
using namespace std;
#include <cstring>
struct stringy{
char * str;
int ct;
};
void set(stringy & s, const char * cs);
void show(const char * s, int times=1);
void show(const stringy & s, int times=1);
int main(){
stringy beany;
char testing[] = "Reality isn't what it is used to be.";
set(beany, testing);
show(beany);
show(beany, 2);
testing[0] = 'D';
testing[1] = 'u';
show(testing);
show(testing, 3);
show("Done!");
return 0;
}
void set(stringy & s, const char * cs){
s.ct = strlen(cs);
strcpy(s.str, cs);
}
void show(const char * s, int times){
while (times-- > 0){
cout << s << endl;
}
}
void show(const stringy & s, int times){
show(s.str, times);
}