I have to read N lines with one of the following 3 formats:
- " Q ": the letter Q .
P k ": the letter P followed by k where k is an integer; A : the letter A followed by k being an integer;
As I do not know if the person goes by P / A or Q first I just have to read a letter.
If the letter is Q, I make the code for the letter. If it is P / A I still have to read an integer and then make the respective P / A code and its number.
My problem is that I make scanf
for the first letter in this way at least:
for(idx = 0; idx < N ; idx++)
scanf("%c",&opc);
Within for
I have some more code. The problem is this. The first time it goes well. The second time it arrives at scanf
of char
the compiler automatically puts the ASCII code character 10 representing the line break.
This happens because scanf
does not clear the ENTERs buffer so I did this:
for(idx = 0; idx < N ; idx++)
scanf("%c\n",&opc);*
I've added \n
to scanf
to it to some extent consume line break.
In this way I get another error that is: (example) if the first input is Q for example it asks me for Q to read it only once.
So I put a Q and nothing happens. I put the second there and it advances and follows normally.