• C

returning structure from function

Compiler error:  "two or more data types in declaration of readData"

The point of data structures is to have objects of various data types right?  I'm guessing a simple syntax error.....


#include<stdio.h>

struct myModel{
    char myChar;
    int myInt;
    double myDouble;
}

struct myModel readData(){
    struct myModel data;
    data.myChar = 'a';
    data.myInt = 1;
    data.myDouble = 5.00;
    return data;
}

int main(){
    struct myModel test = readData();
    return 0;
}
mistagitarAsked:
Who is Participating?
 
efnConnect With a Mentor Commented:
You need a semicolon after the declaration of struct myModel.

--efn
0
 
shivsaCommented:
i think u have to declare like this.

typedef struct myModel{
    char myChar;
    int myInt;
    double myDouble;
}
0
 
mistagitarAuthor Commented:
Thanks efn, I knew it was somthing small.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.