Reputation: 25
#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
Upvotes: 0
Views: 3607
Reputation: 1532
You should create your struct object from (process1 to process6).
Let me give you an example:
#include <stdio.h>
#include <string.h>
typedef struct student
{
int id;
char name[20];
float percentage;
} status;
int main()
{
status record;
record.id=1;
strcpy(record.name, "Orcun");
record.percentage = 86.5;
printf(" Id is: %d \n", record.id);
printf(" Name is: %s \n", record.name);
printf(" Percentage is: %f \n", record.percentage);
return 0;
}
This is why you are getting your error in your main function. So you should create your struct object like:
process1 processOrcun;
You can also check here : https://www.codingunit.com/c-tutorial-structures-unions-typedef
Upvotes: 4
Reputation: 409156
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;
}
Upvotes: 3