64 lines
1.4 KiB
C
Executable File
64 lines
1.4 KiB
C
Executable File
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
[x] Get user input as char
|
|
[x] check if valid input ([ A- Z][ a- z])
|
|
[x] check if valid input ([65-90][97-122])
|
|
[x] if valid, print numerical
|
|
[x] if valid, print ASCII
|
|
[x] if invalid, print "[ERROR] not a valid character [A-Z] or [a-z]"
|
|
[x] if invalid, no further output
|
|
[x] request input repeatedly
|
|
[x] print round number at start
|
|
[x] if "Q" or "q", terminate
|
|
[x] regular output when terminating
|
|
[x] print "GOODBYE" before terminating
|
|
*/
|
|
|
|
unsigned char userchar = 0;
|
|
unsigned int counter = 1;
|
|
|
|
bool charcheck(unsigned char char_)
|
|
{
|
|
if((char_ >= 65 && char_ <= 90) || (char_ >= 97 && char_ <= 122)) // A <= %c <= Z OR a <= %c <= z
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void round_start()
|
|
{
|
|
printf("Round %d:\n", counter);
|
|
counter++;
|
|
printf("%s", "Insert character: ");
|
|
}
|
|
|
|
int main()
|
|
{
|
|
while(1)
|
|
{
|
|
round_start();
|
|
scanf(" %c", &userchar);
|
|
|
|
if (charcheck(userchar) == true)
|
|
{
|
|
printf("%-17s %d\n", "Number:", userchar);
|
|
printf("%-17s %c\n", "ASCII character:", userchar);
|
|
//Q == 81, q == 113
|
|
if (userchar == 81 || userchar == 113) {break;}
|
|
}
|
|
else
|
|
{
|
|
printf("[ERROR] not a valid character [A-Z] or [a-z]\n");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
printf("GOODBYE\n");
|
|
return 0;
|
|
} |