/****************************/ /* Example of a bad routine */ /* By: Brien Beattie */ /****************************/ /* Required header information */ #include typedef enum {false, true} boolean; void GetNameOrNumber(boolean NameOrNumber); char TheName[25]; int AreaCode, FirstBit, Number; /* A main program to test the routine */ /* This program prints out the numbers one to ten (as words) */ main() { GetNameOrNumber(true); GetNameOrNumber(false); printf("\n"); printf("Name: %s\n", TheName); printf("Number: (%03d)-%03d-%04d\n", AreaCode, FirstBit, Number); } /* This example routine is a function to either read a */ /* person's name or read a person's telephone number */ void GetNameOrNumber(boolean NameOrNumber) { if (NameOrNumber) // Test which task must be preformed /* Read a person's name */ { printf("Enter your name: "); scanf("%s", TheName); } else /* Read a person's telephone number */ { char NumString[14]; printf("Enter your phone number [(###)-###-####]: "); scanf("%s", NumString); /* Parse the data entered into three numbers */ NumString[4] = 0; NumString[9] = 0; NumString[14] = 0; AreaCode = atoi(&NumString[1]); FirstBit = atoi(&NumString[6]); Number = atoi(&NumString[10]); } } /******************************************************/ /* This routine performes one of two tasks. */ /* - It has logical cohesion */ /* This routine uses global data */ /* - It is not intimate */ /* This routine is geared toward a specific program. */ /* - It is not portable. */ /******************************************************/