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 8809903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:59:29+00:00 2026-06-14T02:59:29+00:00

Hello for my program I must validate input for multiple arrays in another function.

  • 0

Hello for my program I must validate input for multiple arrays in another function. So say I have an array: barcode[MAX]. I want the user to input their barcodes into this array, so like however many barcodes they have they would input it into the barcode[MAX] variable. I would need to validate this input to make sure that it is proper format, so basically greater than 0, no trailing characters. And this validation needs to come from a separate function.

So it would be something like:

for (i = 0; i < MAX; i++)
{
    printf ("Barcode: ");
    barcode[MAX] = validate();

    printf ("Price: ");
    price[MAX] = validate();
}

that would be in the main function, calling the user to input their barcodes / prices and validating the input in a separate function. But I am not sure how to write a validating function for an array input. I have written one before for just a simple variable but an array confuses me. My previous validating code was like:

do
{
    rc = scanf ("%llf%c", &barcode[MAX], &after);

    if (rc == 0)
    {
        printf ("Invalid input try again: ");
        clear();
    }
        else if (after != '\n')
        {
            printf ("Trailing characters detected try again: ");
            clear();
        }
            else if ()
            {

            }
                else
                {
                    keeptrying = 0;
                }

} while (keeptrying == 1);

but this doesn’t look like it would work for an array variable and that was the code I would use for a non array variable. How can I fix this? Also the two arrays are different data types. barcode is a long long variable and price is a double variable.

  • 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-14T02:59:31+00:00Added an answer on June 14, 2026 at 2:59 am

    You want to iterate over the array so is barcode[i] and not the fix position MAX (barcode[MAX]).

    for (i = 0; i < MAX; i++)
    {
        printf ("Barcode: ");
        barcode[i] = validate();
    
        printf ("Price: ");
        price[i] = validate();
    }
    

    Replace long long float for float, you can’t use long long float in c.

    Validate can be something like this:

    int validate()
    {
        char after;
        float input;
        int rc, keeptrying = 1;
        do
        {
            printf("Give me a code bar :\n");
            rc = scanf ("%f%c", &input, &after);
    
            if (rc == 0)
            {
                printf ("Invalid input try again: \n");
                while ( getchar() != '\n' );
            }
            else if (after != '\n')
            {
               printf ("Trailing characters detected try again: \n");
               while ( getchar() != '\n' );
            }
           else
            keeptrying = 0;
    
        } while (keeptrying == 1);
        return input;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a TCL program for a given input string Hello I
I have the following problem. Let's take the input (wikitext) ======hello((my first program)) world======
I have Hello World code that uses function fhi from another hi.cpp file that
I have this problem when trying to run hello world program using android SDK.
Hello im new to bash scripting, i have a simple program which is not
i m running hello world program in spring which works fine with eclipse but
Let's start with the Hello World program detailed at http://developer.android.com/resources/tutorials/hello-world.html . Let's add the
I'm trying to build a hello-world program here to check my android kit installation.
I am trying to develop my Hello World program in NHibernate. My codes are
I'm just learning Ruby and making a simple Hello World program, put for some

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.