Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created March 6, 2021 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Silva97/7e5e07bd7fa829d02c0231be3cb4f7c6 to your computer and use it in GitHub Desktop.
Save Silva97/7e5e07bd7fa829d02c0231be3cb4f7c6 to your computer and use it in GitHub Desktop.
Just an exercise example.
// 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