Last active
May 10, 2024 13:25
-
-
Save lostsh/432d48a4c44658c56ba96f958c91a1da to your computer and use it in GitHub Desktop.
[ARCHIVED] Cowsay in C99/C17
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
#include <stdlib.h> | |
#include <stdio.h> | |
void showCow(int); | |
void showMessage(int, char**); | |
int length(char*); | |
int main(int argc, char **argv){ | |
if(argc == 1){ | |
printf("Usage: %s [message]\n", argv[0]); | |
return 1; | |
} | |
showMessage(argc, argv); | |
showCow(5); | |
return 0; | |
} | |
void showMessage(int size, char *message[]){ | |
int len = size-2;//count spaces between arguments except first arg and first space | |
for(int i=1;i<size;i++) len+=length(message[i]); | |
printf(" "); | |
for(int i=0;i<len+2;i++) printf("_"); | |
printf("\n<"); | |
for(int i=1;i<size;i++) printf(" %s", message[i]); | |
printf(" >\n "); | |
for(int i=0;i<len+2;i++) printf("-"); | |
printf("\n"); | |
} | |
void showCow(int shiftSize){ | |
char shift[shiftSize]; | |
for(int i=0;i<shiftSize;i++)shift[i] = ' '; | |
shift[shiftSize] = '\0'; | |
printf("%s\\ ^__^\n%s \\ (oo)\\_______\n%s (__) \\ )\\/\\\n%s ||----w |\n%s || ||\n", shift, shift, shift, shift, shift); | |
} | |
int length(char *txt){ | |
int size = 0; | |
while(txt[size] != '\0') size++; | |
return size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example :
Compile :
Execute :
./cow Typical cowsay output!