0

Code problems

It must output whole your input but it doesn't for strange reason(which i don't know) #include <iostream> int main() { char text, *arr = &text; int i = 0; while(std::cin >> text){ arr[i] = text; std::cout << arr[i]; i++; } return 0; } //input ggg //outputs g%g

24th Sep 2018, 6:17 PM
Oleg Storm
Oleg Storm - avatar
3 Respuestas
+ 4
There is no array in your program. When you do array[i] with i > 0 you corrupt a stack of your main function.
24th Sep 2018, 7:33 PM
Sergey Ushakov
Sergey Ushakov - avatar
0
So after i corrupted my stack it does ok, why so?
25th Sep 2018, 3:28 AM
Oleg Storm
Oleg Storm - avatar
0
Your corruption was big enough to change output, but not enough to break program. Try a long input string with different characters.
25th Sep 2018, 3:34 AM
Sergey Ushakov
Sergey Ushakov - avatar