mfd mfd - 13 days ago 6
C Question

Expected primary expression before ';' token

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct PROCESS{
int priority;
int lifecycle;
int ttl;

}process1,process2,process3,process4,process5,process6;

main(){
PROCESS *waiting_queue;
waiting_queue = process1; //this is were I get the error.
waiting_queue =(PROCESS *)malloc(6*sizeof(PROCESS));
if(!waiting_queue){printf("no memory for waiting queue "); exit(0);}


getch();
}


I am trying to create a struct array with pointer. I am getting the error. Expected primary expression before ';' token

Answer

You have multiple problem, but the one causing your error is that you don't define a type PROCESS, but a structure with that name.

When you use typedef to define a structure type, the type-name comes after the structure:

typedef struct
{
    ...
} PROCESS;

The error you have is because you define e.g. process1 as a type, so the assignment (making a pointer point to a type) doesn't make any sense.


Another, and unrelated, problem is how you define the main function. It must be defined to return an int (even if your declaration does that implicitly, it's good to do it explicitly) and to either have void for argument or an integer and an array of pointers to char. In your case it should look like

int main(void) {
    ...
    return 0;
}