I have 2 structs in a "patient records" database program. I have a function for adding new patients that checks if there's an empty element in the patient array, and if so, goes to a function that finds the next patient number.
When I use my 'viewing records' function, the new patient number is there, rather there's some random numbers. And my strings either aren't there or are a single character. I'm probably making some very obvious assignment errors here:
Code:
void addPatient(struct Patient patient[], int max) {
int i = 0, index = 0, vacancy = 0, nextNum;
for (i = 0; !vacancy || i < max; i++) {
if (patient[i].patientNumber == 0) {
vacancy = 1; index = i;
}
} if (vacancy) {
patient[index].patientNumber = nextPatientNumber(patient, max);
// is this right? ^^^^^^^^^
inputPatient(patient + index);
printf("\n*** New patient record added ***\n");
} else {
printf("\nERROR: Patient listing is FULL!\n");
} return;
}
void inputPatient(struct Patient* patient) {
char name[30] = { 0 };
printf("Number: %05d", patient->patientNumber); // << works!
printf("\nName : ");
scanf("%[^\n]", name);
strcpy(patient->name, name); // << only copying 1 char
inputPhoneData(patient);
return; }
void inputPhoneData(struct Phone* phone) // not the whole function {
int select, i, valNum = 1; char phoneNum[11] = { 0 };
strcpy(phone->description, "TBD"); // << doesnt work. why?? return; }