I'm having a problem with a c code, that is testing triangles. I'd like to restrict the input at the first question to a number from 1 - 255. That works so far. But i also want to include a error if the input is wrong.
At the part where the user is asked to type a first, second and third number i'd like it to accept only 0.0 < FLT_MAX. Again i'd like it to prompt an error at wrong input, and then ask again for the number.
Any help would be appreciated.
Thanks,
Dommas
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ROW 255
#define COLUMN 3
#define B 0
#define COL 0
int count;
int x = 0;
int a = 0;
double zahl[ROW][COLUMN];
int main()
{
memset(zahl, 0, sizeof(zahl[0][0]) * ROW * COLUMN);
char input[255];
int first = 0;
//read input
do
{
printf("Please enter the number of triangles to check: ");
if(fgets(input, sizeof(input), stdin) == NULL)
{
return 0;
}
first = atof(input);
} while(first < 1 || first > ROW);
for (count = 0; count < first; count++) {
printf("Please enter the first number of the triplet: ");
scanf("%lf", &zahl[x][COL]);
printf("Please enter the second number of the triplet: ");
scanf("%lf", &zahl[x][COL+1]);
printf("Please enter the third number of the triplet: ");
scanf("%lf", &zahl[x][COL+2]);
x++;
}
}