├── power.c ├── silly.c └── squares.c /power.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /* 5 | *Filename:power.c 6 | *Purpose:Read three numbers and print count number of powers of num 7 | * 8 | */ 9 | int main(){ 10 | int counter=0; 11 | int number,count,modulo; 12 | if(scanf("%d %d %d",&number,&count,&modulo)!=3){ 13 | fprintf(stderr,"Cannot read 3 numbers!!!\n"); 14 | return -1; 15 | } 16 | if(number<2 ||modulo<2){ 17 | fprintf(stderr,"number or modulo is less than 2!!\n"); 18 | return -1; 19 | } 20 | int i; 21 | int base=1; 22 | printf("%d\n",base); 23 | for(i=1;i 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main(int argc, char **argv) 15 | { 16 | int i; 17 | 18 | if (argc != 2) 19 | { 20 | fprintf(stderr, "SYNTAX: %s \n", argv[0]); 21 | return 1; 22 | } 23 | 24 | char *s = "This is a test string, foo bar 123.\n"; 25 | for (i=0; i 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | *Filename:squares.c 8 | *Purpose:draw a square according to the stdin 9 | */ 10 | void drawSquare(int,char); 11 | int main(){ 12 | int len; 13 | int unuse; 14 | char digit; 15 | scanf("%d%d",&len,&unuse); 16 | if(len<=0){ 17 | fprintf(stderr,"the length is less or equal to zero,terminating..\n"); 18 | return 1; 19 | } 20 | printf("The input character is not a printable character. Hex=0x0a\n\n"); 21 | //scanf("%d",&unuse); 22 | //printf("%d",len); 23 | drawSquare(len,' '); 24 | while(scanf("%c",&digit)==1){ 25 | if(isprint(digit)!=0){ 26 | drawSquare(len,digit); 27 | } 28 | else{ 29 | printf("The input character is not a printable character. Hex=0x0%x\n",digit); 30 | } 31 | } 32 | return 0; 33 | } 34 | 35 | 36 | //The function that draw the square 37 | void drawSquare(int n,char digit) 38 | { 39 | int i, j; 40 | for (i = 1; i <= n; i++) 41 | { 42 | for (j = 1; j <= n; j++) 43 | { 44 | if(i==j){ 45 | printf("\\"); 46 | } 47 | else if(j==(n-i+1)){ 48 | printf("/"); 49 | } 50 | else if (i==1 || i==n){ 51 | printf("-"); 52 | } 53 | 54 | else if(j==1 ||j==n){ 55 | printf("|"); 56 | } 57 | else 58 | printf("%c",digit); 59 | } 60 | printf("\n"); 61 | } 62 | printf("\n"); 63 | } 64 | --------------------------------------------------------------------------------