Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8226199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:40:59+00:00 2026-06-07T15:40:59+00:00

I need to validate user input using a separate function. For example, programming is

  • 0

I need to validate user input using a separate function.
For example, programming is asking for input in functionA and validation code should be in FunctionB … I know all the ifs and while statement for validation but I cant figure out how to use two separate function for this… Here is the sample run..

#include <stdio.h>

void get_input (int * inp);
double valid_input (void);

main ()
{
    get_input (&inp);
    valid_input ();
}

void get_input (int *inp)
{
    printf("enter something");
    scanf("%d", &inp);
}

double valid_input ()
{
    // what to put here ?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:41:02+00:00Added an answer on June 7, 2026 at 3:41 pm

    I’m not entirely sure exactly what validation that you’re looking for. If you’re looking simply for validation that the character types you were looking for were entered, Wug’s answer is close.

    If you’re looking for another function that does some validation, this could provide a starting point for you:

    #include <stdio.h>
    
    int get_input (int *integerINput, char *characterInput);
    void valid_input (int inp);
    
    main()
    {
        int integerInput;
        char charInput[2];
    
        // man scanf reports that scanf returns the # of items
        //      successfully mapped and assigned.
        //      gcc 4.1.2 treats it this way.
        if (get_input (&integerInput) < 2)
        {
            printf ("Not enough characters entered.\n");
            return;
        }
    
        valid_input (integerInput);
    }
    
    int get_input (int *integerInput, char *characterInput)
    {
        int inputCharsFound = 0;
    
        printf ("Enter an integer: ");
    
        inputCharsFound += scanf ("%d", inp);
    
    
        printf ("Enter a character: ");
    
        // The first scanf leaves the newline in the input buffer
        //    and it has to be accounted for here.
        inputCharsFound += scanf ("\n%c", characterInput);
    
        printf ("Number of characters found = %d\n", inputCharsFound);
    
        return inputCharsFound;
    }
    
    void valid_input (int inp)
    {
        if (inp > 5)
            printf ("You entered a value greater than 5\n");
        else
            printf ("You entered a value less than 5\n");
    }
    

    EDIT
    HasanZ asked for more details on how to handle more than one variable in the comments below. I’ve updated the code to read in another input character.

    I’ll leave it to you to determine how to best accept the appropriate input and validate that input since you’ve asked in generic terms how to validate in a separate function.

    I would also take a look here for more information on C programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to validate the user input using regular expression. It should be a
I need to validate a user input using getch() only to accept numeric input
I need to validate two user input fields against each other in seam. Field1
I am using javascript to validate user input on my aspx page. I am
Background I need to validate user input in some fields, where these are defining
I'm using jQuery.validity to validate PHP form inputs. I need to skip validation when
I'm currently using the jQuery Validate plugin for my input validation. It is used
I need to validate a user input of about 1,500 characters Allowed characters are
I need to do a user input validation, and I want it validated both
I need to add custom validation(I think) for validating input from an user. Here's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.