frame.c
1 #include <stdio.h> 2 #include <ctype.h> 3 #include <string.h> 4 #include <stdlib.h> 5 6 int get_max_strlen(char *string, char *delim) 7 { 8 int len; 9 int max; 10 int i; 11 char *copystr; 12 char *save_copy; 13 char *token; 14 15 copystr = strdup(string); 16 save_copy = copystr; 17 len = 0; 18 max = 0; 19 token = strtok(copystr, delim); 20 while (token != NULL) 21 { 22 len = strlen(token); 23 if (len > max) 24 max = len; 25 token = strtok(NULL, delim); 26 } 27 free(save_copy); 28 return (max); 29 } 30 31 int main(int argc, char **argv) 32 { 33 int max; 34 int index; 35 int i; 36 char *token; 37 char delim[] = " \n\t\v\f\r"; 38 39 if (argc == 1) 40 return (1); 41 index = 1; 42 while (argv[index] != 0) 43 { 44 max = get_max_strlen(argv[index], delim); 45 i = -1; 46 while (++i < max + 4) 47 printf("*"); 48 printf("\n"); 49 token = strtok(argv[index], delim); 50 while (token != NULL) 51 { 52 printf("* "); 53 printf("%-*s", max, token); 54 printf(" *\n"); 55 token = strtok(NULL, delim); 56 } 57 i = -1; 58 while (++i < max + 4) 59 printf("*"); 60 printf("\n"); 61 index++; 62 } 63 return (0); 64 }