exercises/ex02/adderinclass.c
int read_integer(int * errPoint) {
    char *res;
    char buffer[BUFFER_SIZE];
    int number;
    char *end;

    // read a string
    res = fgets(buffer, sizeof(buffer), stdin);
    if (res == NULL) {
        return -1;
    }

    // check if the length of the string it too long
    if (strlen(buffer) == BUFFER_SIZE) {
        return -2;
    }

    //printf("%s, %d\n", buffer, (int)strlen(buffer));

    // convert to integer
    number = strtol(res, &end, 10);

    // check for invalid input.  Notice that atoi returns 0
    // for invalid input, so we can't allow the used to enter 0.
    if (*errPoint == 0) {
        return -2;
    }
    return number;
}
/* read_integer: Reads an integer from stdin.
*
*   returns: integer
*/
Reads an integer from stdin.
returns: integer
Reads an integer from stdin . returns : integer
int read_integer(int * errPoint) {
    char *res;
    char buffer[BUFFER_SIZE];
    int number;
    char *end;
    res = fgets(buffer, sizeof(buffer), stdin);
    if (res == NULL) {
        return -1;
    }
    if (strlen(buffer) == BUFFER_SIZE) {
        return -2;
    }
    number = strtol(res, &end, 10);
    if (*errPoint == 0) {
        return -2;
    }
    return number;
}
int read_integer ( int * errPoint ) { char * res ; char buffer [ BUFFER_SIZE ] ; int number ; char * end ; res = fgets ( buffer , sizeof ( buffer ) , stdin ) ; if ( res == NULL ) { return -1 ; } if ( strlen ( buffer ) == BUFFER_SIZE ) { return -2 ; } number = strtol ( res , & end , 10 ) ; if ( * errPoint == 0 ) { return -2 ; } return number ; }
read_integer: Reads an integer from stdin.
read_integer : Reads an integer from stdin .
// read a string // check if the length of the string it too long //printf("%s, %d\n", buffer, (int)strlen(buffer)); // convert to integer // check for invalid input.  Notice that atoi returns 0 // for invalid input, so we can't allow the used to enter 0.