MyCowsay
Published on 2007-10-14 18:10:12.
Description
Simple code that outputs a given string in a nice frame.Contents
[Hide]Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 void mycowsay( char * );
6
7 int main( ){
8 char str[50];
9
10 for( ;; ){
11 printf( "Enter string: " );
12 scanf( "%s", str );
13
14 if( !strlen( str) ){
15 printf( "Zero length string, exiting cowardly!\n" );
16 exit( 0 );
17 }
18
19 mycowsay( str );
20 }
21
22 }
23
24 /**
25 * Wraps a string in asterisks
26 *
27 * @param char pointer str str to format
28 *
29 */
30 void mycowsay( char *str ){
31 int asterisks, asterisks2, counter = 0;
32
33 asterisks2 = asterisks = 4 * ( strlen( str ) + 1 ) - 3;
34
35 while( asterisks-- ){
36 printf( "*" );
37 }
38
39 printf( "\n" );
40
41 do{
42 printf( "* %c ", toupper( *(str) ) );
43 }while( *(str++) );
44
45 printf( "\n");
46
47 while( asterisks2-- ){
48 printf( "*" );
49 }
50
51 printf( "\n" );
52
53 }
54
55
2 #include <stdio.h>
3 #include <string.h>
4
5 void mycowsay( char * );
6
7 int main( ){
8 char str[50];
9
10 for( ;; ){
11 printf( "Enter string: " );
12 scanf( "%s", str );
13
14 if( !strlen( str) ){
15 printf( "Zero length string, exiting cowardly!\n" );
16 exit( 0 );
17 }
18
19 mycowsay( str );
20 }
21
22 }
23
24 /**
25 * Wraps a string in asterisks
26 *
27 * @param char pointer str str to format
28 *
29 */
30 void mycowsay( char *str ){
31 int asterisks, asterisks2, counter = 0;
32
33 asterisks2 = asterisks = 4 * ( strlen( str ) + 1 ) - 3;
34
35 while( asterisks-- ){
36 printf( "*" );
37 }
38
39 printf( "\n" );
40
41 do{
42 printf( "* %c ", toupper( *(str) ) );
43 }while( *(str++) );
44
45 printf( "\n");
46
47 while( asterisks2-- ){
48 printf( "*" );
49 }
50
51 printf( "\n" );
52
53 }
54
55
| Code statistics | ||||
|---|---|---|---|---|
| Physical lines | Code lines | Comment lines | Empty lines | Size |
| 54 [ 100.00% ] | 29 [ 53.70% ] | 8 [ 14.81% ] | 17 [ 31.48% ] | 873 bytes |
| [ Download ] |