top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

WRONG input for INTEGER, the program should restart?

+3 votes
82 views

I have a weird requirement and have no clue. I have a variable in C which I want to get it using scanf or something similar but say in pace of integer if one enters non-integer then program should restart.

Any suggestions??

posted Feb 17, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
  1. If the code is in embedded, some hardware changes may also be required whereby, you pull ON/OFF of an IO pin, which in turn tied to the reset pin of the controller/processor, with additional circuit to pull OFF/ON of the reset pin automatically (once reset done, MCU/MPU goes OFF, which need to be started).

  2. If the code is in non-embedded (say PC), you need to structure the code such that an infinite loop continuously runs inside main with multiple conditions (one of the condition to check user input) and you can re-initialize all the variables, and continue executing rest of the code.

Use your imagination and try to draw on paper (flow chart) of what happens in the code, and try to introduce your condition in the flow chart. You will arrive at the answer for your question.

answer Feb 18, 2015 by R.senthil
...