//exercise 1: a simple C program
//http://e...content-available-to-author-only...u.tw/~klim/unix-p/usp-1092.html
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *ptr, c;
char *str
= malloc(sizeof(char) * 256 + 1); char *num
= malloc(sizeof(char) * 16 + 1); int i = 0, j = 0, len;
long sum = 0;
str[i] = c;
i++;
}
str[i] = '\0';
for (i
= 0; i
<= strlen(str
); i
++) { num[j] = str[i];
j++;
if ((str[i] == 32) || (str[i] == '\n')) {
num[j] = '\0';
if ((num[0] == '\0') || (num[0] < 48) || (num[0] > 57)) {
char *num = "0";
}
else {
sum
= sum
+ strtol(num
, &ptr
, 10); }
j = 0;
}
}
}
Ly9leGVyY2lzZSAxOiBhIHNpbXBsZSBDIHByb2dyYW0gCi8vaHR0cDovL2UuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnUudHcvfmtsaW0vdW5peC1wL3VzcC0xMDkyLmh0bWwKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgppbnQgbWFpbigpIHsKCWNoYXIgKnB0ciwgYzsKCWNoYXIgKnN0ciA9IG1hbGxvYyhzaXplb2YoY2hhcikgKiAyNTYgKyAxKTsKCWNoYXIgKm51bSA9IG1hbGxvYyhzaXplb2YoY2hhcikgKiAxNiArIDEpOwoJaW50IGkgPSAwLCBqID0gMCwgbGVuOwoJbG9uZyBzdW0gPSAwOwoJCgl3aGlsZSAoKGMgPSBnZXRjaGFyKCkpICE9IEVPRikgewoJCXN0cltpXSA9IGM7CgkJaSsrOwoJfQoJc3RyW2ldID0gJ1wwJzsKCWZvciAoaSA9IDA7IGkgPD0gc3RybGVuKHN0cik7IGkrKykgewoJCW51bVtqXSA9IHN0cltpXTsKCQlqKys7CgkJaWYgKChzdHJbaV0gPT0gMzIpIHx8IChzdHJbaV0gPT0gJ1xuJykpIHsKCQkJbnVtW2pdID0gJ1wwJzsKCQkJaWYgKChudW1bMF0gPT0gJ1wwJykgfHwgKG51bVswXSA8IDQ4KSB8fCAobnVtWzBdID4gNTcpKSB7CgkJCQljaGFyICpudW0gPSAiMCI7CgkJCX0KCQkJZWxzZSB7CgkJCQlzdW0gPSBzdW0gKyBzdHJ0b2wobnVtLCAmcHRyLCAxMCk7CgkJCX0KCQkJaiA9IDA7CgkJfQkKCX0KCXByaW50ZigiXG4lbGRcbiIsIHN1bSk7Cn0K