say I have 3 strings:
char a[9];
char b[20];
char c[20];
how would I create a third string composed of the contents of the previous strings, bearing in mind that a, b and c are input by the user. when I use strcpy with a and then strcat with b and c and then print the resulting string d, I get rubbish characters. Is this to do with the NULL terminators for each strings or am I doing something else wrong? Thank you
EDIT:
void getBasicDetails(char date_of_birth[9], char first_name[20],
char last_name[20])
{
char temp_dob[9];
char temp_fname[20];
char temp_lname[20];
char file_name[50];
int stop = 1;
printf("Patient's Date of Birth (in format dd/mm/yy) : "); // 2 and 5
while (stop == 1)
{
scanf("%s", &temp_dob);
emptyBuffer();
if ((temp_dob[2] == '/' && temp_dob[5] == '/'))
{
stop = 0;
break;
}
else
{
printf("Enter in format dd/mm/yy\n");
}
}
date_of_birth = temp_dob;
date_of_birth[9] = '\0';
printf("Patient's First Name : ");
scanf("%s", &temp_fname);
emptyBuffer();
first_name = temp_fname;
first_name[20] = '\0';
printf("Patient's Last Name : ");
scanf("%s", &temp_lname);
emptyBuffer();
last_name = temp_lname;
last_name[20] = '\0';
strcat(file_name, first_name);
strcat(file_name, last_name);
strcat(file_name, date_of_birth);
puts(file_name);
}