Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:51:40+00:00 2026-06-06T05:51:40+00:00

I have a struct course and a function for it: typedef struct Course_s {

  • 0

I have a struct “course” and a function for it:

typedef struct Course_s
    {
    char* name;
    int grade;
    } Course;

int courseGetGrade(Course const* course)
    {
    assert(course);
    return course -> grade;
    }

and another struct “transcript” and a function:

typedef struct Transcript_s
    {
    char* name;
    struct Course** courseArray;
    } Transcript;

double tsAverageGrade(Transcript const *t)
    {
    double temp = 0;
    int a = 0;

    while(t -> courseArray[a] != NULL)
        {
        temp = temp + courseGetGrade(t -> courseArray[a]);
        a++;
        }

    return (temp / a);
    }

But I cannot seem to pass the argument t -> courseArray[a] to the function courseGetGrade. I’m a little confused with pointers and how this should be implemented, I just don’t see why it doesn’t work the way it is. The courseArray is an array of Course structs, with a NULL pointer at the end of the array.

I get a warning “passing argument 1 of “courseGetGrade” from incompatible pointer type”. If I try adding “const” before the argument the warning changes to an error: expected expression before “const”.

I’m using plain C.

All help is much appreciated!

Edit. Here is the full compiler output. There are more functions and therefore more warnings in the full output than in the code I originally posted:

transcript.c: In function âtsAverageGradeâ:
transcript.c:66: warning: passing argument 1 of âcourseGetGradeâ from incompatible pointer type
course.h:27: note: expected âconst struct Course *â but argument is of type âstruct Course *â
transcript.c: In function âtsSetCourseArrayâ:
transcript.c:89: error: invalid application of âsizeofâ to incomplete type âstruct Courseâ
transcript.c:94: warning: assignment from incompatible pointer type
transcript.c: In function âtsPrintâ:
transcript.c:114: warning: passing argument 1 of âcourseGetNameâ from incompatible pointer type
course.h:24: note: expected âconst struct Course *â but argument is of type âstruct Course *â
transcript.c:114: warning: passing argument 1 of âcourseGetGradeâ from incompatible pointer type
course.h:27: note: expected âconst struct Course *â but argument is of type âstruct Course *â
transcript.c: In function âtsCopyâ:
transcript.c:126: warning: passing argument 2 of âtsSetCourseArrayâ from incompatible pointer type
transcript.c:80: note: expected âstruct Course **â but argument is of type âstruct Course ** constâ

Edit.2 Here is the function causing the error in line 89:

void tsSetCourseArray(Transcrpt *t, Course **courses)
    {
    assert(t && courses);
    free(t -> courseArray);
    int a = 0;
    while(courses[a] != NULL)
        a++;
    t -> courseArray = malloc(sizeof(struct Course) * (a+1));

    a = 0;
    while(courses[a] != NULL)
        {
        t -> courseArray[a] = courseConstruct(courseGetName(courses[a]), courseGetGrade(courses[a]));
        a++;
        }

    t -> courseArray[a] = NULL;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:51:43+00:00Added an answer on June 6, 2026 at 5:51 am

    Change:

    typedef struct Transcript_s
    {
        char* name;
        struct Course** courseArray;
    } Transcript;
    

    to:

    typedef struct Transcript_s
    {
        char* name;
        Course** courseArray; /* 'Course' is a typedef for 'struct Course_s'. */
    } Transcript;
    

    Also the following is incorrect, for two reasons:

    t -> courseArray = malloc(sizeof(struct Course) * (a+1));
    

    struct Course should be Course but more importantly it should be Course* as space needs to be allocated for the Course*: t->courseArray is a Course**. Change to:

    t -> courseArray = malloc(sizeof(Course*) * (a+1));
    

    Also, the following will not free the Course instances in the courseArray, it will only free the array of pointers:

    free(t -> courseArray);
    

    You need to iterate over courseArray and free each individual element and then free the array of pointers:

    while (t->courseArray[a] != NULL)
    {
        free(t->courseArray[a]->name); /* If name was dynamically allocated. */
        free(t->courseArray[a]);
    }
    free(t -> courseArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct struct Packet { int senderId; int sequenceNumber; char data[MaxDataSize]; char*
Ok so I have struct like this typedef struct { float x; float y;
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int
I have a struct as follows, with a pointer to a function called length
I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count;
I have a large C structure (about 40 members, int and char[]) which I
Consider: template < typename Something > boost::function<void()> f() { typedef typename Something::what type; return
I have a function in a struct that sorts a vector in the struct.
I made a simple function, which get's a file's size. int file_size( char *
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.