Created
March 6, 2021 00:30
-
-
Save Silva97/7e5e07bd7fa829d02c0231be3cb4f7c6 to your computer and use it in GitHub Desktop.
Just an exercise example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an exercise example. | |
#include <stdio.h> | |
#include <stdlib.h> | |
void crep(int character, unsigned int number); | |
int main(int argc, char **argv) | |
{ | |
if (argc < 2) | |
{ | |
fputs("Error: Please specify the box length. Example: ./box 16\n", stderr); | |
return 1; | |
} | |
unsigned int length = strtol(argv[1], NULL, 10); | |
if (length % 2) | |
{ | |
length++; | |
} | |
unsigned int middle = length / 2; | |
char symbol = '*'; | |
crep(symbol, length); | |
for (int x = 1; x < middle - 1; x++) | |
{ | |
printf("%c%*c%*c%*c\n", symbol, x, symbol, length - (x * 2) - 2, symbol, x, symbol); | |
} | |
printf("%c%*c%*c\n", symbol, middle - 1, symbol, middle - 1, symbol); | |
for (int x = middle - 2; x > 0; x--) | |
{ | |
printf("%c%*c%*c%*c\n", symbol, x, symbol, length - (x * 2) - 2, symbol, x, symbol); | |
} | |
crep(symbol, length); | |
return 0; | |
} | |
void crep(int character, unsigned int number) | |
{ | |
while (--number) | |
putchar(character); | |
putchar('\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment