I have a little problem.
In the following problem I am trying to display an array of pointers in a separate function. The commented section displays the "name" variable correctly, however, the code in display() gives me a funky result with odd letters. Why is that??
Code:
static int count = 0;
typedef struct Record{
char *name;
int age;
float hbp;
float lbp;
float riskFactor;
} Record;
static Record *patients[30];
void display()
{
int k;
for (k=0;k<count;k++)
{
printf("%d %s",count, patients[k]->name);
}
}
void enter(){
patients[count] = (Record *)malloc(sizeof(Record));
char name[20];
int age;
float hbp, lbp;
printf("name: ");
scanf("%s", name);
printf("age: ");
scanf("%d", &age);
printf("high bp: ");
scanf("%f", &hbp);
printf("low bp: ");
scanf("%f", &lbp);
patients[count]->name = name;
patients[count]->age = age;
patients[count]->hbp = hbp;
patients[count]->lbp = lbp;
count++;
// int k;
// for (k=0; k<count;k++)
// {
// printf("%s", patients[k]->name);
// }
}