1

I have a struct of pointers and a global pointer to use in functions declared after main. Now declaring the functions with those same name of pointers is fine. But when I call it within another function (because its like a menu type program), I kept getting different types of errors.. Like expression is needed, unexpected type, etc. My question is simply how to I call the parameters for the function to work. I haven't used C in years so the solution might seem simpler than it sounds like. The code below will show you what I mean.

StudentPtr studentArray StudentPtr** studentArray struct StudentPtr *studentArray *StudentPtr studentArray[] (Pretty much moving the pointers around and using struct as prefix)

typedef struct Student {
    char *firstName;
    char *lastName;
    char *id;
    char *email;
} Student, *StudentPtr;

//Prototypes:
int fillData(StudentPtr studentArray,char* f, char* l, char* id, char* e,int n);
int displayData(StudentPtr studentArray, int n);
int displayDataAll(StudentPtr studentArray);

int main()
{
return 0;
}

int command(char line[])
{
//other code here
//some more code..
//......

//error below
if(lineSize==0)    /* If the command is empty, asks again for a command */
    {
        return 0;
    }

    else
    {
        if(strncmp(line,"1",lineSize)==0)
        {reset();}

        else if(strncmp(line,"2",lineSize)==0)
        {fillData(StudentPtr studentArray,char* f, char* l, char* id, char* e,int n);} //the first parameter here

        else if (strncmp(line,"3",lineSize)==0)
        {modify(StudentPtr studentArray,char* f, char* l, char* id, char* e,int n);} //here as well

        else if(strncmp(line,"4",lineSize)==0)
        {displayDataAll(StudentPtr studentArray);} //here too


        else if(strncmp(line,"5",lineSize)==0)
        {return 1;}
        else
        {noComm();}
    }

    return 0;
}

//example of the functions supposed to be used
int fillData(StudentPtr studentArray,char* f, char* l, char* id, char* e,int n)
{
    //get the start of the nth record
    //Ptr arithmetic
    StudentPtr currentStudentptr = studentArray+(n-1);

    //allocate memory for the character pointers
    currentStudentptr->firstName =malloc(sizeof(char)*20);
    strcpy(currentStudentptr->firstName,f);

    //... same for others

    return 0;

}

The calling of the function here should properly call the functions that are further down.

1 Answer 1

2

You are mixing syntax for function declaration and definition with syntax for calling a function:

    {fillData(StudentPtr studentArray,char* f, char* l, char* id, char* e,int n);} //the first parameter here

In a function call you mustn't specify the type. You only provide the arguments:

    {fillData(studentArray, f, l, id, e, n);}

You do not show any variable definiton. Therefore I cannot tell if the variables have correct types or if you need to add some & operators here and there... That is the reason why a minimum complete verifyable example is mandatory.

Sign up to request clarification or add additional context in comments.

4 Comments

there other parameters work fine.. and I understand I could have made it shorter, didn't cross my mind. My apologies. It's just that first parameter I'm having trouble with.
More importantly you should have make it complete. With all parts needed to compile.
I doubt that you will not get any errors for other parameters when you fix the first one.
alrighty.. well like you mention I was basically declaring when I shouldnt, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.