【发布时间】:2018-12-05 19:26:02
【问题描述】:
int numOfProcesses = 0;
printf("How many processes would you like to enter: ");
scanf("%d",&numOfProcesses);
struct process p[numOfProcesses];
int counter = 1;
// This is the quantum printf(argv[1]);
// This is the type to run printf(argv[2]);
if(argv[2] = "FCFS"){
while(counter < numOfProcesses){
int temp;
p[counter];
printf("For process %d: \n",counter);
printf("Enter the pid: ");
scanf("%d", p[counter].pid);
printf("Enter the burst time: ");
scanf("%d",p[counter].burstTime);
printf("Enter the arrival time: ");
scanf("%d",p[counter].arrivalTime);
counter++;
}
我试图让我的代码保存一个结构数组,并允许我编辑数组中结构的属性,但一切都会导致段错误。我在做什么?
【问题讨论】:
-
scanf("%d", p[counter].pid);->scanf("%d", &p[counter].pid);。接下来的两个也一样。 -
打开编译器警告。
-
if(argv[2] = "FCFS"){-->>if(!strcmp(argv[2] , "FCFS")){ -
p[counter];什么都不做。 -
你从 1 开始,但数组从 0 开始。