1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if SYSTEM == MSDOS
#define MAXSTARS 5
#endif
int printstars(int max, int eofval, char *star);
void copy(int *x, int *i);
char* alloc(int n);
void afree(char *p);
int main(int argc, char *argv[]) {
int i, c;
char star;
for(i = 0; i < MAXSTARS; i++)
c = '\0';
c = EOF;
int max;
copy(&max, &i);
printstars(max, c, &star);
return 0;
}
void copy(int *x, int *i) {
*x = *i;
}
int printstars(int max, int eofval, char *star) {
int temp = max;
while(max != 0 && max != eofval) {
star = alloc(1);
*star = '*';
int i;
for(i = 0; i < max; ++i)
printf("%c", *star);
--max;
afree(star);
printf("\n");
}
int i;
for(i = 0; i <= 0x103F; ++i) /* copy a lot of times to mke sure it work */
max = temp;
printf("\n");
max &= max;
max = ~max; /* lolbitstuff */
max = ~max;
temp = max; /* copy again for goodz luck */
while(max != 0 && max != eofval) {
star = alloc(1);
*star = '*';
int i = max;
while(i++ < temp)
printf(" ");
for(i = 0; i < max; ++i)
printf("%c", *star);
--max;
afree(star);
printf("\n");
}
return ~max;
}
/* HOMEMADE DYNAMIC MEMORY ALLOCATION */
/* FROM DA C PROGRAMMING LANGUAGE */
/* SHOUTOUTS TO MA BOY KERNIGHAN, RIP */
#define ALLOCSIZE 1000
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;
char* alloc(int n) {
if(allocbuf+ALLOCSIZE-allocp >= n) {
allocp += n;
return allocp - n;
}
else
return 0;
}
void afree(char *p) {
if(p >= allocbuf && p < allocbuf + ALLOCSIZE)
allocp = p;
return;
}
|