Got this code, which is part of a larger program, but in order to debug it I have separated it from the rest of it.
Code:
#include <stdio.h>
struct PatientDetails {
char F_name[15];
char L_name[20];
int QueueType;
};
typedef struct PatientDetails Patient;
Patient CurrentPatient;
Patient *PatientPtr;
PatientPtr = &CurrentPatient;
void AbsrbPatient()
{
puts ("\nPlease type patient's first name");
flushall();
gets (PatientPtr->F_name);
printf ("\nfirst name is %s", PatientPtr->F_name);
puts ("\nPlease type patient's last name");
flushall();
gets (PatientPtr->L_name);
printf ("\nlast name is %s", PatientPtr->L_name);
}
int main(void)
{
AbsrbPatient();
}
Running it (also in original program) I get:
error C2040: 'PatientPtr' : 'int ' differs in levels of indirection from 'struct PatientDetails *'
warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'struct PatientDetails *'
Nevertheless, if I run the same code with a little modification it runs OK, but it doesn’t looks very nice…
Code:
#include <stdio.h>
struct PatientDetails {
char F_name[15];
char L_name[20];
int QueueType;
};
typedef struct PatientDetails Patient;
void AbsrbPatient()
{
Patient CurrentPatient;
Patient *PatientPtr;
PatientPtr = &CurrentPatient;
puts ("\nPlease type patient's first name");
flushall();
gets (PatientPtr->F_name);
printf ("\nfirst name is %s", PatientPtr->F_name);
puts ("\nPlease type patient's last name");
flushall();
gets (PatientPtr->L_name);
printf ("\nlast name is %s", PatientPtr->L_name);
}
int main(void)
{
Patient CurrentPatient;
Patient *PatientPtr;
PatientPtr = &CurrentPatient;
AbsrbPatient();
}
How should I right the upper version better ?