Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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 continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

1. How does Kiwi Experience maintain a continual customer focus?

Answered: 1 week ago