Bad code:
// compute GCD
while((remainder = numerator % denominator) != 0)
{
numerator = denominator;
denominator = remainder;
}
return numerator;
// Copy strig
dst[count = strlen(src)] = 0;
while(i-- > 0)
dst[i] = src[i];
Good code:
// Read and store characters
char *dst = buffer;
while((ch = fgetc(inputfile)) != EOF)
*dst++ = ch;
*dst++ = '\0'
// Copy n characters or less from a C-string
while (*src && n-- > 0)
*dst++ = *src++;
*dst++ = '\0';
Is this good or bad code?
// Make month, day, year integers look more formal
while (cin >> month >> day >> year)
cout << AddSuffix(day) << " day of " << LookupName(month) << ", " << MakeFourDigit(year) << endl;

New Topic/Question
Reply

MultiQuote







|