/*=======================================================================*/ #define PROGRAMMER "SOLUTIONS, Nofrills" #define PROG_CODE "SOLN" #define COURSE "ECE-1021" #define YEAR (2004) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "HW4" #define REVISION (0) #define TITLE "String Output" #define SUBTITLE "Last Modified on 21 SEP 04" #define EMAIL "ece1021@eas.uccs.edu" #define FILENAME "4_0SOLN0.c" /*=======================================================================*/ /*=======================================================================*/ /* WAIVED COMPILER WARNINGS */ /*=======================================================================*/ /* Linker Warning: No module definition file specified: using defaults Reason for Waiver: Can't suppress. Does not have adverse impact. */ /*=======================================================================*/ /* NOTES TO THE USER/GRADER */ /*=======================================================================*/ /* */ /*=======================================================================*/ /* PROBLEM STATEMENT */ /*=======================================================================*/ /* Create and test a function, PutS(), that outputs a string of characters beginning with the character located at the address passed to the function and ending with the last character prior to a NUL character. */ /*=======================================================================*/ /* DEVELOPMENT NOTES */ /*=======================================================================*/ /* */ /*=======================================================================*/ /* PSEUDOCODE */ /*=======================================================================*/ /* */ /*=======================================================================*/ /* DEVIATIONS FROM SUBMITTED PSEUDOCODE */ /*=======================================================================*/ /* */ /*=======================================================================*/ /*=======================================================================*/ /* CODE SECTION */ /*=======================================================================*/ /*=======================================================================*/ /*== INCLUDE FILES ======================================================*/ #include /* stdout, putc(), printf() */ /*== MACRO DEFINITIONS (OBJECT-LIKE) ====================================*/ #define FALSE (0) #define TRUE (!FALSE) #define BLANKLINE printf("\n") #define MARGIN (2) /* Left Margin in PrintHeader() */ #define INDENT_SIZE (2) /* Indent relative to */ #define LMARG printc(' ', MARGIN) /* Print Left Margin */ #define INDENT printc(' ', INDENT_SIZE) /* Indent relative to margin */ #define TSYM 'T' #define FSYM '-' #define DEFAULT_BASE (10) /* Must be 2 through 36 */ /*== EXIT CODE DEFINITIONS ==============================================*/ #define EXIT_PASS (0) #define EXIT_FAIL (1) /*== MACRO DEFINITIONS (FUNCTION-LIKE) ==================================*/ #define PutC(c) (putc((char)(c),stdout)) #define PutD(d) (PutC( (char) ((d)<10)?('0'+(d)):('A'+(d)-10) )) #define Put_u(n) (Put_ubase((n), DEFAULT_BASE)) #define PutH_u(n)(Put_ubase((n), 16)) /*== TYPEDEF STATEMENTS =================================================*/ /*=======================================================================*/ /* STRUCTURE DEFINITIONS and FUNCTIONS */ /*=======================================================================*/ /*=======================================================================*/ /* SUPPORT FUNCTIONS ( functions not called directly by main() ) */ /*=======================================================================*/ int printc(char c, int n) { while ( (n--) && (c == putc(c, stdout)) ); /* EMPTY LOOP */ return n; } /*=======================================================================*/ /* INTEGER OUTPUT FUNCTIONS */ /*=======================================================================*/ int PutV_u(unsigned int n) { unsigned int m; int i, count; /* Set m to the largest power or ten <= n */ for (m = 1; n/m >=10; m*=10) /* EMPTYLOOP */; /* Print out the digits in n one-by-one */ for (count = 0; m > 0; m /= 10) { for(i = 0; n >= m; i++) n -= m; PutD(i); count++; } return count; } int PutV_i(int n) { if (n < 0) { PutC('-'); return 1 + PutV_u(-n); } return PutV_u(n); } int PutS(const char *s) { int i; for(i = 0; '\0' != s[i]; i++) PutC(s[i]); return i; } /*=======================================================================*/ /* PRIMARY FUNCTIONS ( functions called directly by main() ) */ /*=======================================================================*/ /*== FUNCTION PROTOTYPES (to Document Support Functions) ================*/ int printc(char c, int n); int PutV_u(unsigned int n); int PutV_i(int n); int PutS(const char *s); /*== PRIMARY FUNCTIONS ==================================================*/ void PrintHeader(void) { LMARG; printc('=', (78 - MARGIN)); putc('\n', stdout); LMARG; printf("Course....... %s-%i (%s %i)\n",COURSE,SECTION,TERM,YEAR); LMARG; printf("Programmer... %s (%s)\n", PROGRAMMER, PROG_CODE); LMARG; printf("Assignment... %s (Rev %i) ", ASSIGNMENT, REVISION); printf("(Source Code in %s)\n", FILENAME); LMARG; printf("Description.. %s\n", TITLE); LMARG; printf(" %s\n", SUBTITLE); LMARG; printc('=', (78 - MARGIN)); putc('\n', stdout); } void MyPrintHeader(void) { /* Top Border */ LMARG; printc('=', (78 - MARGIN)); putc('\n', stdout); /* LINE #1 */ LMARG; PutS("Course....... "); PutS(COURSE); PutS("-"); PutV_i(SECTION); PutS(" ("); PutS(TERM); PutS(" "); PutV_i(YEAR); PutS(")\n"); /* LINE #2 */ LMARG; PutS("Programmer... "); PutS(PROGRAMMER); PutS(" ("); PutS(PROG_CODE); PutS(")\n"); /* LINE #3 */ LMARG; PutS("Assignment... "); PutS(ASSIGNMENT); PutS(" (Rev "); PutV_i(REVISION); PutS(") "); PutS("(Source Code in "); PutS(FILENAME); PutS(")\n"); /* LINE #4 */ LMARG; PutS("Description.. "); PutS(TITLE); PutS("\n"); /* LINE #5 */ LMARG; PutS(" "); PutS(SUBTITLE); PutS("\n"); /* Bottom Border */ LMARG; printc('=', (78 - MARGIN)); putc('\n', stdout); } /*=======================================================================*/ /* MAIN FUNCTION */ /*=======================================================================*/ /*== FUNCTION PROTOTYPES (to Document Primary Functions) ================*/ void PrintHeader(void); int main(void) { PrintHeader(); BLANKLINE; MyPrintHeader(); return EXIT_PASS; } /*=======================================================================*/ /* END OF SOURCE CODE FILE */ /*=======================================================================*/