can somebody say me what im missing?
int main() {
char eingabe[100];
cin >> eingabe;
eingabe[strlen(eingabe)]='\0';
cout << eingabe << endl;
}
But i get this: Segmentation fault
:(
If cin contains a line longer then 99 characters, the cin >> operator writes beyond the eingabe[] buffer end. This is wrong and likely to generate the segfault.
You may want to use the std::string class, rather then a char[] buffer.
If you have some good reason to use a char[100] buffer, then
cin.getline(eingabe,100) is what you need.
eingabe[strlen(eingabe)]='\0';eingabe[strlen(eingabe)]='\0'for a minute.s[strlen(s)]is already0, right? How do you thinkstrlen()managed to determine its return value? And to answer the question,std::stringis what you're missing.std::stringand safe yourself the trouble. Your program will break if the input is more than 99 chars long.