This code unite is a part of a bigger code of a database in C. This part takes grades of students. requirements are to use typedef unsigned char uint8 instead of a simple int. For the life of me I can't make it work. When I use %c in scanf it skips. In print if it prints the first digit sometimes. So this is the code with int and it's working fine, how do I make it work with uint8 or unsigned char???
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <inttypes.h>
#include <string.h>
//typedef unsigned char uint8;
typedef unsigned int uint8;
int main(void)
{
uint8 grades_t[3], gr_c, g_temp;
for (gr_c = 0; gr_c < 3;)
{
printf("please enter the grade (0-100) of subject no%d: ", gr_c+1);
scanf("%d", &g_temp);
if (g_temp < 0 || g_temp > 100) //only accept values between 0-100
{
printf("please enter valid grade from 0 - 100!\n");
gr_c --; //if value is out of range, decrement
}
else //store value
{
grades_t[gr_c] = g_temp;
}
gr_c++;
}
printf("grade = %d\n", grades_t[0]); //unite test
printf("grade = %d\n", grades_t[1]);
printf("grade = %d", grades_t[2]);
return 0;
}