0

I want to break for loop by pressing the enter and my inputs iare indexs of an array (c++)

I have no idea why my code doesn't work help me please char a[100]; for (int i=0 ; i>-1 ; i++) { cin >> a[i]; if(a[q]=='\n') break; }

28th Oct 2019, 2:32 PM
bavan
bavan - avatar
3 Réponses
+ 2
Actually I wrote it by mistake😅 (a[i]=='\n' )I wanted to write . I want to get char until I press the enter but whenever I ran it and pressed the enter, the loop would'nt break😑
28th Oct 2019, 6:22 PM
bavan
bavan - avatar
+ 1
Rather difficult trying to do this in SoloLearn. See this page has an example for reading character continuously, and stop upon finding a certain character. But the example was written in C, and the character to break the loop was a period (easy to change though). http://www.cplusplus.com/reference/cstdio/getchar/ I'm still not getting what you are trying to do/achieve by this BTW.
28th Oct 2019, 7:24 PM
Ipang
0
What exactly are you trying to do or achieve here? Your loop risks for infinity while your char array buffer is limited to 99 characters. Where is the declaration of variable <q>? if(a[q] == '\n') break;
28th Oct 2019, 3:26 PM
Ipang