Skip to content

Instantly share code, notes, and snippets.

@lostsh
Created November 22, 2021 21:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lostsh/feee5576d5cbb83ab3888d78d6e861e1 to your computer and use it in GitHub Desktop.
Save lostsh/feee5576d5cbb83ab3888d78d6e861e1 to your computer and use it in GitHub Desktop.
parrotsay
#include <stdio.h>
void showMessage(int, char**);
void showParrot(int);
size_t strlen(char*);
int main(int argc, char **argv){
if(argc <= 1){
printf("Usage: %s [message]\n", argv[0]);
return -1;
}
showMessage(argc, argv);
showParrot(7);
return 0;
}
void showParrot(int shiftSize){
char shift[shiftSize];
for(int i=0;i<shiftSize;i++)shift[i] = ' ';
shift[shiftSize] = '\0';
printf("%s\\ _________ \n%s \\ //// \\\\\\\\ \n%s \\ // \\\\ \n%s \\ //,-, ,-,\\\\ \n%s ||( @ ) ( @ )|| \n%s \\\\ '-` .___. `-' // \n%s || |^ ^| || \n%s \\\\ \\ / // \n%s \\\\\\ \\v/ /// \n%s \\\\ // \n%s // \\\\ \n%s /||\\ /||\\ \n%s // || || \\\\ \n%s // || || \\\\ \n%s |/ /| |\\ \\| \n%s | // \\\\ | \n%s | // ,___, \\\\ | \n%s |_/ | | | | \\_| \n%s \\____/ \\____/ \n%s \\__/ \\__/ \n%s || || \n%s || || \n%s || || \n%s '--' '--' \n", shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift, shift);
}
void showMessage(int argc, char **argv){
int len = argc-2; // Ignore first arg and first space
for(int i=1;i<argc;i++) len+=strlen(argv[i]);
printf(" ");
for(int i=0;i<len+2;i++) printf("_");
printf("\n<");
for(int i=1;i<argc;i++) printf(" %s", argv[i]);
printf(" >\n ");
for(int i=0;i<len+2;i++) printf("-");
printf("\n");
}
size_t strlen(char *str){
unsigned short int i = 0;
while (str[i] != '\0') i++;
return i;
}
@lostsh
Copy link
Author

lostsh commented Nov 22, 2021

Compile

gcc parrot.c -o parrotsay

Execute

./parrotsay Typical parrotsay output \!

@lostsh
Copy link
Author

lostsh commented Nov 22, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment