Search code examples
cuser-inputtokenize

How to get both a number and character from the user?


There are two variables a and b, and I want to get data from the user. The data can be a number from 1 to 1000 or #, and they should be apart by a space.

So how to get this kind of input from the user?


Solution

  • In general, this is too broad a scenario to provide exact answer. However, I'll be happy to provide you the idea.

    • Read user input using fgets().
    • Tokenize the input using delimiter (space, here) by strtok().
    • Use appropriate converter functions (example: strtol()) to check and convert the inputs.

    Now choose a language, write the code and come back if you have any specific issue / question to be addressed / answered.