# Thread: Preludes: verify int code

1. ## Preludes: verify int code

Im trying to learn how to verify an integer from some code Prelude posted a earlier. I can follow most of it but there are a few things Im confused on, first here is his code:

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

enum ISVAL { VALID, INVALID };
typedef enum ISVAL val_t;

static val_t checknumber ( char *astr )
{
while ( *astr != '\0' )
if ( !isdigit ( *astr++ ) )
return INVALID;
return VALID;
}

int main(void)
{
char astr[10];
if ( fgets ( astr, 10, stdin ) != NULL ) {
if ( astr[strlen(astr)-1] == '\n' )
astr[strlen(astr)-1] = '\0';
if ( checknumber ( astr ) == INVALID )
printf ( "Invalid integer\n" );
else
printf ( "Your number is %d\n", atoi ( astr ) );
}
system("PAUSE");
return 0;
}```
Ok as I siad the code I can somewhat follow but the first few lines
Code:
```enum ISVAL { VALID, INVALID };
typedef enum ISVAL val_t;

static val_t checknumber ( char *astr )```
Thats where I get lost. I have tried looking in up in my book and on the net but I didnt get much.

Can someone please break those three lines down so I might better understand?

Thanks

2. this enumerates two values, VALID = 0, INVALID = 1 as type of ISVAL.

enum ISVAL { VALID, INVALID };

this typedef in the most basic explaination gives "enum ISVAL" an alias of val_t so val_t can be used anywhere in place of "enum ISVAL" and vice versa

typedef enum ISVAL val_t;

this declares a static(explained in a minute), named checknumber that takes a charater string as an reguement and returns a val_t alias to "enum ISVAL".

the 'static' keyword specifies that this function is not visible outside the file in which it is defined.

static val_t checknumber ( char *astr )

3. ## thanks

could not have been better worded for me to understand.

Thank you!
Rye