int do_intrev(int argc, char **argv) { unsigned long n = 0; if (argc > 2) { n = atoi(argv[2]); } else { int c; skipc(stdin, ' '); while ((c = getc(stdin)) != EOF) { if (c == '\n') break; if (c >= '0' && c <= '9') { n *= 10; n += c-'0'; } } } if (n == 0) { intrev_usage(argv[0]); return -1; } printf("%ld\n", intreverse(n)); return 0; }
Blk* add(Blk *a1, Blk *a2) { Blk *p; int carry, n, size, c, n1, n2; size = length(a1)>length(a2)?length(a1):length(a2); p = salloc(size); rewind(a1); rewind(a2); carry=0; while(--size >= 0) { n1 = sfeof(a1)?0:sgetc(a1); n2 = sfeof(a2)?0:sgetc(a2); n = n1 + n2 + carry; if(n>=100) { carry=1; n -= 100; } else if(n<0) { carry = -1; n += 100; } else carry = 0; sputc(p,n); } if(carry != 0) sputc(p,carry); fsfile(p); if(sfbeg(p) == 0) { c = 0; while(sfbeg(p) == 0 && (c = sbackc(p)) == 0) ; if(c != 0) salterc(p,c); truncate(p); } fsfile(p); if(sfbeg(p) == 0 && sbackc(p) == -1) { while((c = sbackc(p)) == 99) { if(c == -1) break; } skipc(p); salterc(p,-1); truncate(p); } return(p); }
Blk* removc(Blk *p, int n) { Blk *q, *r; rewind(p); while(n>1) { skipc(p); n -= 2; } q = salloc(2); while(sfeof(p) == 0) sputc(q,sgetc(p)); if(n == 1) { r = div(q,tenptr); release(q); release(rem); q = r; } release(p); return(q); }