Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

type problem

  • 04-11-2009 12:51pm
    #1
    Registered Users, Registered Users 2 Posts: 6,054 ✭✭✭


    alright guys, I was just wondering if anyone could help me out.

    iv developed a simple program in c for a project.

    for all of the user input choices, iv used ints.

    but, now im on the error checking stage and if the user enters a char, the program gets all messed up.

    I was wondering how to combat this? Iv searched online but everything is very complicated compared to what we have done so far.

    any help would be really appreciated, as would an explanation so Im not just blindly copying:o


Comments

  • Registered Users, Registered Users 2 Posts: 3,766 ✭✭✭Reku


    Without knowing more detail on the specific processing the user input undergoes in order to reach a result I can only suggest these two solutions:
    1. cast the input to an integer (not a great solution if there's actualy merit to user input as opposed to just requesting an input to save using a random number generator);
    2. apply a check to the input and if it isn't an integer instead of continuing the normal operation give a message to the user stating that only integer inputs are allowed.


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    As per point 2. above: Take in the input as a string or char[], check that each charachter is numerical using isdigit() and then convert the string/char[] to an int.


Advertisement