CSCD-255
2015-01-09


Material actually covered 2015-01-08

Data types:

Data type name

   Size in bytes

   Conversion character

char 1 %c
short int 2 %hd
long int 4 %ld
int 4 %d
float 4 %f
double 8 %lf

Note:  C specifies that the long int be longer than the short int.  The specification of the default int is that it must have a size between that of the short int and that of the long int.

Some C compilers have an additional data type for a 64-bit (8 byte) integer and may have yet more data types.

Sizes.txt    Sizes.c

Character strings:

 * C does not have a string data type.  Instead it has the convention
 * that an array (list) of characters stores a character string, with
 * the condition that the last character not be a printing character
 * but rather the "null" character, with the value zero.
StringVar.txt    StringVar.c

End material covered 2015-01-08



Printf part two:  displaying the contents of variables, constants, and expressions:
 printf ( <control string> [ , data ] )
as in printf ("Pi is around %f\n", 355.0 / 113);
Note:  preceding the f in %f can be a decimal point and number.  This controls the number of digits to show after the decimal place.  If none is given, C uses 6.

printf_two.txt    printf_two.c

Example of setting a table format:  printf_table.txt    printf_table.c

Accepting user keyboard data into variables:  scanf(<control string>, <target location>)

The control string is just like the printf control string, except here it is almost always quoted text.

For numerical data, the target location is the ampersand ('&') followed by the numerical variable name.

For a character string, the target location is just the name of the char array.

The reasons for these strange rules will be explained in Chapters 24 and 25.

Remember, %s will accept only one white-space delimited word.  Ch. 19 will show how to get around this.

Demonstration:  scanfDemo.txt    scanfDemo.c