I would like to know why Jack and George's names fail to print. I tried adding another member in the struct the names get printed normally, why is that ? I would really appreciate it if someone can help. Here's the code:
#include <stdio.h>
typedef unsigned short int u16;
typedef unsigned char u8;
typedef struct
{
u8 name[10];
u16 salary;
u16 bonus;
u16 deduction;
//u8 x;//why does the printed name get ruined
//without this?
}employee;
void main (void)
{
employee arr[3]={{.name = "John"},{.name =
"Jack"},{.name = "George"}};
u16 i = 0;
u16 sum = 0;
for (i = 0; i < 3; i++)
{
printf("\nPlease enter %s's Salary:",arr[i].name);
scanf(" %d",&arr[i].salary);
printf("\nPlease enter %s's Bonus:",arr[i].name);
scanf(" %d",&arr[i].bonus);
printf("\nPlease enter %s's Deduction:",arr[i].name);
scanf(" %d",&arr[i].deduction);
sum = sum + arr[i].salary + arr[i].bonus - arr[i].deduction;
}
printf("\nTotal value needed is: %d",sum);
}