Home > Back-end >  consult
consult

Time:03-10

This code, I am hoping to enter the capital letters, lowercase output, this can run repeatedly until the input for a particular character, but I found that no matter what the input values, "erroe will somehow" output again, the ball ball brain help me
# include
Int main ()
{
Printf (" please enter the capital letters, if you want to quit please enter \ '2 \ \ n ");
char a,b;
While (a!='2')
{
The scanf (" % c ", & amp; A);
If (a>='A' & amp; & A<='Z')
{
B=a + 32;
Printf (" % % \ n c is the lowercase letter "c, a, b);
}
The else
{
Printf (" error "\ n");
}
}
return 0;
}

CodePudding user response:

Reference:
 # include 
Int main ()
{
Printf (" please enter the capital letters, if you want to quit please enter \ '2 \ \ n ");
char a,b;
While (a!='2')
{
The rewind (stdin);
The scanf (" % c ", & amp; A);
If (a>='A' & amp; & A<='Z')
{
B=a + 32;
Printf (" % % \ n c is the lowercase letter "c, a, b);
}
The else
{
Printf (" error "\ n");
}
}

return 0;
}

CodePudding user response:

this key: after reading one character, clear the buffer, Windows, Linux method to you, see the system use, without extra trouble your invisible characters input also play out,
 # include 
Int main ()
{
Printf (" please enter the capital letters, if you want to quit please enter \ '2 \ \ n ");
Char a;
While (a!='2')
{
The scanf (" % c ", & amp; A);
The fflush (stdin);//clear the buffer for win
//setbuf (stdin, NULL);//clear the buffer for Linux
If (a>='A' & amp; & A<='Z')
Printf (" % % \ n c is the lowercase letter "c, a, a + 'a' - 'a');
Else if (a==' ')
Printf (" input error, char is: space \ n ");
Else if (a=='\ n')
Printf (" input error, char is: enter \ n ");
The else
Printf (" input error, char is: % c \ n ", a);
}
return 0;
}

CodePudding user response:

The rewind (stdin);//Windows/Linux generic input buffer