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
Wrap
Text File
|
2023-02-26
|
3KB
|
122 lines
/*
Chapter 1 - Variables.c
Demonstration of defining and displaying variables plus keyboard input
*/
#include "stdio.h"
#define MAX 25.2
#define clear_screen printf("\223")
int global_var;
main()
{SHIFT-+}
char choice, choice_array[10],choice2[10];
int x,y;
double z=1.07682;
x=1;
y=2;
clear_screen;
printf("As with all of the programs on the disk");
printf("\nthe greater benefit is gained through");
printf("\nboth listing the source code and seeing");
printf("\nhow this relates to what appears on");
printf("\nscreen... press any key");
getchar();
clear_screen;
printf("The screen was cleared with the command");
printf("\nclear_screen which was defined at the");
printf("\nbeginning of the program.");
printf("\n\nThe backslash n after the quotes (you");
printf("\ncannot see it on screen) forces text to");
printf("\nappear on a new line ");
printf("not joined on.");
/*
displaying numbers
*/
cursor(10,7); printf("Displaying Numbers");
printf("\n\nThe integer x has a value of %d",x);
printf("\nThe integer y has a value of %d",y);
printf("\nObject x =%d Object y =%d",x,y);
printf("\n\nThe constant MAX = %f",MAX);
printf("\n\nThe object z of type double = %g",z);
printf("\ncan also be displayed as %012g",z);
printf("\nor %12g",z);
cursor(22,7); printf("Press any key");
getchar();
/*
getting single key input from the keyboard
*/
clear_screen;
cursor(5,7); printf("Keyboard Input");
printf("\n\nPress a letter or a number key ");
choice=getchar();
printf("\nYou pressed the %c key",choice);
/*
getting string input using gets
*/
printf("\n\nEnter a short word followed by <RETURN> ");
gets(choice_array);
printf("\nThe whole word is %s",choice_array);
printf("\nThe first 2 chrs are %.2s",choice_array);
printf("\n\n Press any key");
getchar();
/*
getting input using scanf
*/
clear_screen;
cursor(5,1); printf("Keyboard Input Using scanf");
printf("\n\nEnter a short word followed by <RETURN> ");
scanf("%s",choice2);
printf("\nThe whole word is %s",choice2);
printf("\n\nEnter an whole number :");
scanf("%d",&x);
/* notice the "&" sign; used when inputing numbers */
printf("\nThe number is %d",x);
printf("\n\n Press any key");
getchar();
printf("\n\nHopefully loading c-menu....");
exec("c-menu");
{SHIFT--}