/*****************************************
Author : QianWen
Time : 2017/12/21
From : 第八章第4题
******************************************/
#include "stdafx.h"
#include<iostream>
using namespace std;
#include<cstring>
struct stringy{
char* str;
int ct;
};
void set(stringy &, char[]);
void show(const char* a, int n = 1);
void show(const stringy & b, int n = 1);
int main(){
stringy beany;
char testing[] = "reality isn't what it used to be. ";
set(beany, testing);
show(beany);
show(beany, 2);
testing[0] = 'D';
testing[1] = 'u';
show(testing);
show(testing, 3);
show("done!");
cin.get();
return 0;
}
void set(stringy & sc, char * tests){
sc.ct = strlen(tests);
sc.str = new char[sc.ct + 1];
strcpy(sc.str,tests);
}
void show(const char* a, int n){
while (n-- > 0){
cout << n <<a<<"\n";
}
}
void show(const stringy & b, int n){
while (n-- > 0){
cout <<n<< b.str<<"\n";
}
}