C “;”之前应为主表达式代币

C “;”之前应为主表达式代币,c,C,我正在尝试用指针创建一个结构数组。我得到了错误。“;”之前应为主表达式token您有多个问题,但导致错误的原因是您没有定义类型进程,而是定义了具有该名称的结构 使用typedef定义结构类型时,类型名称位于结构之后: #include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct PROCESS{ int priority; int lifecycle

我正在尝试用指针创建一个结构数组。我得到了错误。“;”之前应为主表达式token

您有多个问题,但导致错误的原因是您没有定义类型进程,而是定义了具有该名称的结构

使用typedef定义结构类型时,类型名称位于结构之后:

#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();       
}
您所犯的错误是因为您将例如process1定义为类型,因此将指针指向类型的赋值没有任何意义

另一个不相关的问题是如何定义主函数。必须将其定义为返回int,即使您的声明隐式地返回int,最好显式地返回,并且参数为void,或者是整数和指向char的指针数组。你的情况应该是这样的

typedef struct
{
    ...
} PROCESS;

您应该从process1到process6创建struct对象

让我举个例子:

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

你也可以在这里查看:

谢谢你,我的朋友;我按照你的指示做了,但给出了相同的错误。@mfd等待队列的类型是什么?进程1的类型是什么?这些类型兼容吗?答案是否?所以不,你不会得到相同的错误,但会得到不同的错误。此外,该分配是无用的,因为您随后直接重新分配等待队列。它们的类型是进程。你的想法启发了我,我找到了解决办法;等待队列=&process1;谢谢。@mfd不太好。等待队列的类型是PROCESS*,这与process1的类型非常不同,process1是PROCESS。这就是为什么你需要操作员的地址。再说一次,如果你只是想在下一个语句中重新分配waiting_queue,为什么要这样做呢?你把类型和结构的声明搞得一团糟。获取错误的行中的AFAICT、process1是一个类型,而不是一个结构,这使得该语句有点非法。
#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;
}
process1 processOrcun;