-2

Im am trying to write a program that collects the information of students. I am using an array of students(structs)

typedef struct {
  char name[50];
  struct Course* course;
}Student;

and in my main() i did this

Student* stds = (Student*) malloc(app.std_cnt * sizeof(*stds) );

getStdData(stds);

here is the getStdData function

void getStdData(struct Student *students){

 int i;
 char name[50];

 Student std;

 printf("\n");

 for(i = 0; i < app.std_cnt; i++){

    printf("std [%i] name : ",i+1);


    scanf("%s",&name);

    strcpy(std.name,name);

    students[i] = std;

 }
}

when i compile i get

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

gpa.c
gpa.c(124): error C2440: '=': cannot convert from 'Student' to 'Student'

can anyone tell me what i'm doing wrong? and why is is complaning about a Student to Student conversion? are they not of the same type?

  • 1
    Possible duplicate: [Difference between 'struct' and 'typedef struct' in C?](http://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c) – paulsm4 Jun 04 '16 at 19:30

1 Answers1

5

In C, struct Student and Student may be two different types. Student comes from your typedef and struct Student would come from

struct Student { /* ... */ };

So your function should be

void getStdData(Student *students)

For a good discussion of the situation, consider this answer.

Community
  • 1
  • 1
hcs
  • 1,514
  • 9
  • 14