I am creating an application where visitors enter their data and that data go to an array. Also applications has some limitations, the user can enter their first and last name up to 20 characters.
My question would be, what capasity should I indicate in the structure? Maybe 1024 or only 20?
Also, what scan method I should use to get that data, because I use scanf ("% [^ \ n]% * c")
but maybe it would be safer to use gets()
or fgets ()
? I also check the input length with strlen
in my program, but I don't know if it's really needed.
typedef struct Guests
{
char Name[20];
char LastName[20];
} Guests
Update:
char name[20];
printf("Please, enter name:");
scanf("%[^ \ n]s", name);
while(check_Input_Name(name)==1 || strlen(name)>=20)
{
printf("You not entered numbers OR name was too long\n");
printf("Please, try again: ");
scanf("%[^ \ n]s", name);
}
bool check_Input_Name(char *Name) {
for(int i=0; Name[i]; ++i)
{
if(isalpha(Name[i])==0 && Name[i]!=' ')
{
return 1;
}
}
if (isupper(Name[0])==0)
{
return 1;
}
for(int i=0; Name[i]; ++i)
{
if(Name[i]==' ')
{
if (isupper(Name[i+1])==0)
{
return 1;
}
}
}
return 0;
}