In the code below, when I run it, and if I entered more than 30 characters at runtime, it will not read linesNum1 and text[] .
Therefore, I think that it stores an extra character from array1[30] and uses it in linesNum1 .
So, how can I clear the program cache or make it cin linesNum1 and text[] , even if I entered more characters than array1 can hold?
char array1[30]; for (int i = 0; i<30; i++) cin >> array1[i]; int linesNum1; cin >> linesNum1; int linesNum2 = linesNum1*80; char text[linesNum2]; for (int i = 0; i < linesNum2; i++) cin >> text[i]; for (int i = 0; i < linesNum2; i++) cout << text[i];
source share