Simple filtration process for two number sum (note 88)

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

int log_to_stderr;

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

    while ((n = read(STDIN_FILENO, line, MAXLINE)) > 0) {
        line[n] = 0;        /* null terminate */
        if (sscanf(line, "%d%d", &int1, &int2) == 2) {
            sprintf(line, "%d\n", int1 + int2);
            n = strlen(line);
            if (write(STDOUT_FILENO, line, n) != n)
                err_sys("write error");
        } else {                                                                                                             
            if (write(STDOUT_FILENO, "invalid args\n", 13) != 13) 
                err_sys("write error");
        }   
    }   
    exit(0);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Charlotte at December 28, 2013 - 9:01 AM