+ 1

My while statement is not functioning properly. Please explain why. It doesnt wait for taking my input for char rep.?

#include <stdio.h> using namespace std; char rep; int main() { while (rep!='n') { printf ("the loop is on\n Do you want to repeat? y/n \n"); scanf("%n", &rep); } } it doesnt wait for taking my input into rep, the code repeats automatically. why?

8th Feb 2017, 5:26 PM
Logesh S
Logesh S - avatar
4 Réponses
+ 1
so what should i write instead?
8th Feb 2017, 5:32 PM
Logesh S
Logesh S - avatar
+ 1
so what should i write instead?
8th Feb 2017, 5:32 PM
Logesh S
Logesh S - avatar
0
%n bro ...its character scanf mai dekh
8th Feb 2017, 5:30 PM
Shreyance Gupta
Shreyance Gupta - avatar
0
%c instead %n ...char:%c
8th Feb 2017, 5:34 PM
Shreyance Gupta
Shreyance Gupta - avatar