int main(){
char *Statement = "Hello! How are you today? I am well, thankyou.";
char *Replace_statement = "Hello";
char is_this_state[] = "";
cout << sizeof( Replace_statement ) << endl;
for( int i = 0; i < sizeof( Replace_statement ); i++ ){
is_this_state[ i ] = *( Statement + i );
}
cout << Replace_statement << endl;
cout << is_this_state << endl;
getchar();
return 0;
}
Ok so I enter this code and what I get is a bunch of nonsense. I can't display a
print screen. I'm trying to get replace_statement to copy into is_this_state.
I'd suggest using std::string atleast until you get used to memory management. If for some reason you need to use char arrays, while not being safe, here's one way of accomplishing what I believe is what you're trying to do:
1 2 3 4 5 6
constchar *statement = "Hello! How are you today? I am well, thankyou.";
constchar *replace_statement = "Hello";
char is_this_state[512];
unsignedint replacement_size = strlen(replacement_statement);
strncpy(is_this_state, statement, replacement_size);