training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

ex94.c (859B)


      1 /* Exercise 9.4 */
      2 
      3 #include <stdio.h>
      4 
      5 int main(void)
      6 {
      7    unsigned int num = 40000;
      8    int hex, hour, minute, second;
      9    char s[] = "This is a practice string", *ptr;
     10 
     11    printf("\n%-15.8u\n\n", num);
     12 
     13    printf("Hex value: ");
     14    scanf("%i", &hex);
     15    printf(": %i\n", hex);
     16 
     17    printf("\n%+d\n", 200);
     18    printf("%d\n", 200);
     19 
     20    printf("\n%#x\n", 100);
     21 
     22    ptr = s;
     23    while( *ptr != 'p' && ptr != NULL )
     24       printf("%c", *ptr++);
     25 
     26    printf("\n\n%09.3f\n", 1.234);
     27 
     28    printf("\nTime: ");
     29    scanf("%d%*c%d%*c%d%*c", &hour, &minute, &second);
     30    printf("hour[%d] minute[%d] second[%d]\n", hour, minute, second);
     31 
     32    printf("\nstring: ");
     33    scanf("\"%[^\"]s", s);
     34    printf("string: %s\n", s);
     35 
     36    printf("\nTime[2]: ");
     37    scanf("%*c%d:%d:%d", &hour, &minute, &second);
     38    printf("%d %d %d\n", hour, minute, second);
     39 
     40    return 0;
     41 } /* E0F main */
     42