Question: I already wrote the pattern part code, my question is how to use getchar() in main function to only read 191 or 919, and discard

I already wrote the pattern part code, my question is how to use getchar() in main function to only read "191" or "919", and discard whatever follows the number. which is only the first three number matters. how to use getchar() to do that. (don't use strings).

I already wrote the pattern part code, my question is how to

Operation

  1. The program first prints a blank line.
  2. It prompts the user "Enter either 191 or 919, anything else will quit: ".
  3. It reads the input value from the same line of the above message.
  4. It prints a blank line after reading the input.
  5. Depending on the input value, the program displays one of the three outputs as shown in the above screenshot.
  6. If the input is neither 191 nor 919, or a value not beginning with 191 or 919, the program quits after a final message "Good bye!". Otherwise, it repeats step 1 to 5. That is, the program keeps running for an input of 191 or 919. It stops only if the input is neither 191 nor 919, or a value not beginning with 191 or 919.

Specifications

  1. As described in step 5 of operation, the program execution quits immediately if an input is not 191 or 919 or a value beginning with 191 or 919. For instance, when prompted, an input of 22 or -4.67 or abc or $191, +919, etc. will cause the program execution to print "Good bye!" and stop, while 191 or 919 or 191&919 or 191.3 or 91955 or 191 =8, etc. will result one of the two output prints (as shown in the screenshot) and execution continues. Hint: while loop, check returned value of scanf().
  2. If a message prompt is followed by no input but an Enter or Return key pressed, the program does nothing and keeps waiting for an input. *This is not shown in the above console screenshot but you may test it using the given .exe file.
  3. Program output format must match exactly what is shown in the above screenshot. Hint: nesting for loops, i.e., for loops within for loop.
  4. proj1.c doesn't allow to use arrays or any special data structure.
  5. proj1.c doesn't allow to include any hard coded string literals such as "11", "333333", "666666 666666", etc.
  6. In addition to the main() function, proj1.c implements two more functions: do_191() and do_919().
  7. The main() calls do_191() if an input is 191 or a value beginning with 191. It calls do_919() for an input of 919 or a value beginning with 919.
  8. Both of the above two functions have no input parameters and do not return a value. You may use prime.c (p.190, Chapter 9) as a reference for coding functions. Otherwise, it is very similar to how you do and call methods in Java.
  9. proj1.c must be coded with good coding style. You may use prime.c (p.190, Chapter 9) or any book program examples as a reference of good coding style.
  10. proj1.c must compile directly with gcc in command line. Using any IDE is not required.

C:\3515\Proj1>proj1 Enter either 191 or 919, anything else will quit: 191 11 2222 333333 44444444 5555555555 666666666666 77 88 9999 888 6666 5555555555 44444444 333333 2222 11 Enter either 191 or 919, anything else will quit: 919 9999999999999999 88888888 88888888 ???? 666666 55555 4444 333 22 1. 22 333 4444 55555 666666 777???? 7?????? 666666 55555 4444 333 22 22 333 4444 55555 666666 ?????? 999999999999999999 Enter either 191 or 919, anything else will quit: 88888888 88888888 fh6x78 Good bye! C:\3515\Proj1>_

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!