Programming in C

(Barry) #1
Character Arrays 111

}
while ( numberToConvert != 0 );

// display the results in reverse order

printf ("Converted number = ");

for (--index; index >= 0; --index ) {
nextDigit = convertedNumber[index];
printf ("%c", baseDigits[nextDigit]);
}

printf ("\n");
return 0;
}


Program 7.7 Output


Number to be converted? 10
Base? 2
Converted number = 1010


Program 7.7 Output (Rerun)


Number to be converted? 128362
Base? 16
Converted number = 1F56A


The constQualifier


The compiler allows you to associate the constqualifier with variables whose values
will not be changed by the program.That is, you can tell the compiler that the specified
variables have a constant value throughout the program’s execution. If you try to assign a
value to a constvariable after initializing it, or try to increment or decrement it, the
compiler might issue an error message, although it is not required to do so. One of the
motivations for the constattribute in the language is that it allows the compiler to place
your constvariables into read-only memory. (Normally, the instructions of your pro-
gram are also placed into read-only memory.)


Program 7.7 Continued
Free download pdf