Hey guys I am making a program with the use of a constructor for the first time. I have everything working except I am not sure I can add hello on to my pre existing string world when I pass it to the alter function.
Code:
class Prep{
char string[40];
public:
void print()
{
printf("%s");
}
int alter(char s[], int sz);
Prep(char str[]);
};
Prep::Prep(char str[])
{
strcpy(str,string);
}
int Prepender::alter(char s[], int sz)
{
}
int main(void){
char s[40];
char s2[10];
int rc;
strcpy(s,"world");
strcpy(s2,"there");
Pre("hello"); //calls constructor, hello is
//stored inside object
h.print(); //prints hello to the screen
//this next printf will print:
// alter returned: 1. String is: hello world
rc=h.alter(s, 40); //s1 is big enough to add hello
printf("alter returned: %d. String is: %s\n",rc,s1);
//this next printf will print:
// alter returned: 0. String is: there
rc=h.alter(s2, 10); //s2 is not big enough to add hello
printf("alter returned: %d. String is: %s\n",rc,s2);
}