Hi there,
I would like to let the following code keep asking for correct value if the value enter cannot vaildate by myvaild_addr(). Could you give me some hint to make it work. Thanks in advance.
#include<stdio.h>
#include<string.h>
myvaild_addr(input, a, b, c, d)
{
if ( strtok(NULL, ".") != NULL )
printf("Invalid address! Please enter again: ");
else if ( ( a < 1 ) || ( b < 1 ) || ( c < 1 ) || ( d < 1 ) || ( a > 254 ) || ( b > 254 ) || ( c > 254 )
|| ( d > 254 ) )
printf("Invalid address! Please enter again: ");
}
myaddr_class(a, b, c, d)
{
if ( ( a > 0 ) && ( a < 127 ) )
return "A";
else if ( ( a > 127 ) && ( a < 192 ) )
return "B";
else if ( ( a > 191 ) && ( a < 224 ) )
return "C";
else if ( ( a > 223 ) && ( a < 240 ) )
return "D";
else if ( ( a > 239 ) && ( a < 256 ) )
return "E";
}
main()
{
char input[100];
int a, b, c, d, output;
printf("Please enter a valid IP address: ");
scanf("%s", &input);
a = atoi(strtok(input, "."));
b = atoi(strtok(NULL, "."));
c = atoi(strtok(NULL, "."));
d = atoi(strtok(NULL, "."));
myvaild_addr(input, a, b, c, d);
output = myaddr_class(a, b, c, d);
printf("It is a class %s address!\n", output);
}