//// Variable definitions ////
char c;
char buff[60];
int n;
/////// Main Program //////////
void
main()
{ printf("Sample program : Console input/output\n\n");
printf("Enter a letter : ");
gets(buff); if (buff[0]=='\0') // If the 1st character
of buff is NULL
exit(0); // then the string is empty c=buff[0];
printf("The 1st character is '%c' (%d decimal - %x
hex) \n", c,c,c);
printf("Enter a number < 256 : ");
scanf("%d", &n); // Use scanf to input numbers
if (n>255)
printf("Out of range !\n");
else
printf("The character with value %d is
%c\n\n", n,n);
}
Back to top or to Previous Page or to Next Page