Question
I wrote a program: #include /**/ int main(){ int i = 1; while(i !=0){ printf(Hit Enter to quit, or Enter an indenfier: ); char c;
I wrote a program:
#include /**/
int main(){
int i = 1;
while(i !=0){ printf("Hit Enter to quit, or Enter an indenfier: "); char c; int count = 0; int status = 1; char a; if ((c=getchar())==' '){ printf("Thanks for your input. "); break; }else{ while( (c = getchar()) != ' '){ count++;
// if this is the first character of identifire, then it should be either '_' or alphabets if(count == 1){ if((c != '_') && !(c >='A' && c= 'a' && c ='A' && c= 'a' && c = '0' && c
if(count == 0 || status == 0) printf("Invalid "); else printf("Valid ");
}
return 0; }
This giving me the output below:
It is wrong because it eaxm the valid and invalid from second like 1 in the a1 just skip a in the a1.
But If I deleate the following part:
if ((c=getchar())==' '){ printf("Thanks for your input. "); break; }else{
Then the results are correct, however there is no stop of calling for an input.
How can I fix this to have the program end when type in nothing or type in a specific key?
And the same time always test the validility from the beginning.
CAUsers 54985 Documents\C-Free Projects Study\mingw5MSt Hit Enter to quit or Enter an indenfier Invalid Hit Enter to quit or Enter an indenfier: Invalid Hit Enter to quit or Enter an indenfier: Invalid Hit Enter to quit or Enter an indenfier: Invalid Hit Enter to quit or Enter an indenfier: as Walid Hit Enter to quit or Enter an indenfier: al Invalid Hit Enter to quit or Enter an indenfier: a2 Invalid Hit Enter to quit or Enter an indenfier: Thanks for your input. Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started