6 puts("prog size_of_mem_to_alloc");
10 long parse_human_number(char* num
) {
14 size_t l
= strlen(num
);
16 if(l
&& l
< sizeof(buf
)) {
18 ret
= 1024 * 1024 * 1024;
19 else if(num
[l
-1] == 'M')
21 else if(num
[l
-1] == 'K')
26 return atol(buf
) * ret
;
33 int main(int argc
, char** argv
) {
36 if (argc
!= 2) return syntax();
37 mem
= parse_human_number(argv
[1]);
38 if((buf
= malloc(mem
))) {
39 fprintf(stdout
, "malloc %lu bytes succeeded.\n", mem
);
42 fprintf(stdout
, "malloc %lu bytes failed.\n", mem
);