Filtering procedure to two the number of summation, using standard I/O (note 91)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
#include "apue.h"

int log_to_stderr;

int
main(void)
{
    int     int1, int2;
    char    line[MAXLINE];

    if (setvbuf(stdin, NULL, _IOLBF, 0) != 0)
        err_sys("setvbuf error");
    if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)
        err_sys("setvbuf error");

    while (fgets(line, MAXLINE, stdin) != NULL) {
        if (sscanf(line, "%d%d", &int1, &int2) == 2) {
            if (printf("%d\n", int1 + int2) == EOF)
                err_sys("printf error");
        } else {                                                                                                             
            if (printf("invalid args\n") == EOF)
                err_sys("printf error");
        }   
    }   
    exit(0);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Stanley at December 26, 2013 - 8:25 PM