a question on pointers, structs and arrays
The following program serves no purpose other than to help me understand the interaction between pointers, structs and arrays. There are two problems that I cannot figure out.
First, when executed, theStudentPtr->name does not display the string passed to the function.
Second, when you uncomment the printf at line 21, the number variable in the student struct goes haywire. This seems like a really bizarre thing to happen.
So, I have only really confounded my understanding with this little program. Anyway, if anyone can help me through this, that would be tops.
char name ;
struct student * getStudent(char aName, int nr);
int numb = 10;
char name = "Davo";
struct student *theStudentPtr;
theStudentPtr = malloc(sizeof(struct student));
theStudentPtr = getStudent(name, numb);
//printf("name: %s \n\n", name);
printf("name: %s \nnumber: %i\n", theStudentPtr->name, theStudentPtr->number);
struct student * getStudent(char *aName, int nr)
struct student aStudent, *aStudentPtr;
aStudent.number = nr;
aStudentPtr = &aStudent;