home *** CD-ROM | disk | FTP | other *** search
/ Light / Light_Vol.1_June_1992_Datasphere_Publications_Disk_1_of_2_Side_A.d64 / variables.c < prev   
Text File  |  2023-02-26  |  3KB  |  122 lines

  1. /*
  2.  
  3.    Chapter 1 - Variables.c
  4.  
  5.    Demonstration of defining and displaying variables plus keyboard input
  6.  
  7. */
  8.  
  9.  
  10. #include "stdio.h"
  11.  
  12. #define MAX 25.2
  13. #define clear_screen printf("\223")
  14.  
  15. int global_var;
  16.  
  17. main()
  18. {SHIFT-+}
  19.  
  20.    char choice, choice_array[10],choice2[10];
  21.    int x,y;
  22.    double z=1.07682;
  23.  
  24.    x=1;
  25.    y=2;
  26.  
  27.    clear_screen;
  28.  
  29.    printf("As  with all of the programs on the disk");
  30.    printf("\nthe  greater  benefit  is gained through");
  31.    printf("\nboth  listing the source code and seeing");
  32.    printf("\nhow  this  relates  to  what  appears on");
  33.    printf("\nscreen... press any key");
  34.  
  35.    getchar();
  36.  
  37.    clear_screen;
  38.  
  39.    printf("The  screen was cleared with the command");
  40.    printf("\nclear_screen  which  was  defined at the");
  41.    printf("\nbeginning of the program.");
  42.  
  43.    printf("\n\nThe  backslash  n  after the quotes (you");
  44.    printf("\ncannot see it on screen)  forces text to");
  45.    printf("\nappear on a new line ");
  46.    printf("not joined on.");
  47.  
  48. /*
  49.  
  50.   displaying numbers
  51.  
  52. */
  53.  
  54.    cursor(10,7); printf("Displaying Numbers");
  55.  
  56.    printf("\n\nThe integer x has a value of %d",x);
  57.    printf("\nThe integer y has a value of %d",y);
  58.    printf("\nObject x =%d     Object y =%d",x,y);
  59.  
  60.    printf("\n\nThe constant MAX = %f",MAX);
  61.    printf("\n\nThe object z of type double = %g",z);
  62.    printf("\ncan also be displayed as %012g",z);
  63.    printf("\nor %12g",z);
  64.  
  65.    cursor(22,7); printf("Press any key");
  66.    getchar();
  67.  
  68. /*
  69.  
  70.   getting single key input from the keyboard
  71.  
  72. */
  73.  
  74.    clear_screen;
  75.    cursor(5,7); printf("Keyboard Input");
  76.  
  77.    printf("\n\nPress a letter or a number key  ");
  78.    choice=getchar();
  79.    printf("\nYou pressed the %c key",choice);
  80.  
  81. /*
  82.  
  83.   getting string input using gets
  84.  
  85. */
  86.  
  87.    printf("\n\nEnter a short word followed by <RETURN>  ");
  88.    gets(choice_array);
  89.    printf("\nThe whole word is %s",choice_array);
  90.    printf("\nThe first 2 chrs are %.2s",choice_array);
  91.  
  92.    printf("\n\n       Press any key");
  93.    getchar();
  94.  
  95. /*
  96.  
  97.   getting input using scanf
  98.  
  99. */
  100.  
  101.    clear_screen;
  102.  
  103.    cursor(5,1); printf("Keyboard Input Using scanf");
  104.  
  105.    printf("\n\nEnter a short word followed by <RETURN>  ");
  106.    scanf("%s",choice2);
  107.    printf("\nThe whole word is %s",choice2);
  108.  
  109.    printf("\n\nEnter an whole number :");
  110.    scanf("%d",&x);
  111.    /* notice the "&" sign; used when inputing numbers */
  112.    printf("\nThe number is %d",x);
  113.  
  114.    printf("\n\n       Press any key");
  115.    getchar();
  116.  
  117.  
  118.    printf("\n\nHopefully loading c-menu....");
  119.    exec("c-menu");
  120.  
  121. {SHIFT--}
  122.  
  123.