guys I was trying to put several different strings like these:
cap
to
cat
card
two
too
up
boat
boot
into a char* array like this:
char* result[9]
and after assigning every one of those strings into the array with a for loop, I found that all the elements in the array is the same, which is "boot".
My code and result are down here:
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char* result[9];
for(int counter=0;counter<9;counter++)
{
string temp;
getline(cin,temp);
result[counter]=(char*) temp.c_str();
cout<<result[counter]<<endl;//correct
}
cout<<endl;
cout<<endl;
for(int counter=0;counter<9;counter++)
cout<<result[counter]<<endl;//false
}
This line works well,
cout<<result[counter]<<endl;//correct
and it prints all the different words like:
cap
to
cat
card
two
too
up
boat
boot
but somehow, this line
cout<<result[counter]<<endl;//false
it only prints "boot" nine times. I really can't see the reason here and I am hoping you guys can give me a hand, thx!