I am having a structure defined in person.h file
struct person{
char firstName[11];
char familyName[21];
char telephone[11];
int isStudent;
};
Now I want to take input of firstName,familyName etc.
So I did something like this :
void AddRecord(struct person person[20],int currentElemetCount,int maxCount){
getFirstName(person[currentElemetCount].firstName);
getFamilyName(person[currentElemetCount].familyName);
}
In other commons.c file I define these functions,
void getFirstName(char firstName[10]){
printf("Enter First Name : ");
scanf("%10s", firstName);
}
void getFamilyName(char familyName[20]){
printf("Enter Family Name : ");
scanf("%20s", familyName);
}
But when I execute this program, in actual case I want that if user enter more than 10 characters for first name then simply ignore them. But here they are getting assigned to familyName and am not able to input anything for familyName.
What can be the reason ? Please help.
Say if input is "avshgvdshvdhsdhsdhsdhdh" a very long string. Then I want firstName char array as "avshgvdshv" . But with this code remaining "dhsdhsdhsdhdh" string is getting assigned to familyName array, which I dont want.