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.