Hello,
i have the following code:
typedef struct
{
char *matrikelnr;
}student;
int main (void)
{
student *studall[2];
char tVal[10];
studall[0] = (student*)mallo c(sizeof(studen t));
strcpy(tVal,"12 345");
studall[0]->matrikelnr = tVal;
printf("studall[0]->matrikelnr: %s\n",studall[0]->matrikelnr);
studall[1] = (student*)mallo c(sizeof(studen t));
strcpy(tVal,"12 346");
studall[1]->matrikelnr = tVal;
printf("studall[1]->matrikelnr: %s\n",studall[1]->matrikelnr);
printf("studall[0]->matrikelnr: %s\n",studall[0]->matrikelnr);
return 0;
}
output:
studall[0]->matrikelnr: 12345
studall[1]->matrikelnr: 12346
studall[0]->matrikelnr: 12346
My Question: How can i get for stuall[0] the first value 12345? Could any one please help me.
thanks in advance.
Maryam
i have the following code:
typedef struct
{
char *matrikelnr;
}student;
int main (void)
{
student *studall[2];
char tVal[10];
studall[0] = (student*)mallo c(sizeof(studen t));
strcpy(tVal,"12 345");
studall[0]->matrikelnr = tVal;
printf("studall[0]->matrikelnr: %s\n",studall[0]->matrikelnr);
studall[1] = (student*)mallo c(sizeof(studen t));
strcpy(tVal,"12 346");
studall[1]->matrikelnr = tVal;
printf("studall[1]->matrikelnr: %s\n",studall[1]->matrikelnr);
printf("studall[0]->matrikelnr: %s\n",studall[0]->matrikelnr);
return 0;
}
output:
studall[0]->matrikelnr: 12345
studall[1]->matrikelnr: 12346
studall[0]->matrikelnr: 12346
My Question: How can i get for stuall[0] the first value 12345? Could any one please help me.
thanks in advance.
Maryam
Comment