gpt4 book ai didi

c - 我想在 c 中实现一个结构。在 FOR LOOP 部分,没有通过 scanf 获取 P[0].processname 它继续下一部分

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:01 25 4
gpt4 key购买 nike

<分区>

我的代码是

//header files

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

//declare structure for process

struct process
{
char pr; //process name
int A,ex,end,period;
};

struct process P[10];
int main()
{
int N,i;//no. of process
printf("enter number of task \n");
scanf("%d",&N);
printf(" enter processname executiontime period ");

for(i=0;i<N;i++)
{
printf("\n P[%d] . process name=",i);
scanf("%c", &P[i].pr);
printf("\n P[%d] . execution time =",i);
scanf("%d", &P[i].ex);
printf("\n P[%d] . period=",i);
scanf("%d", &P[i].period);
P[i].A=0;
P[i].end = P[i].A + P[i].ex; //here A=0
}
printf("processname\texecutiontime\tperiod\n");
for(i=0;i<N;i++)
{
printf("%c\t%d\t%d\n", P[i].pr,P[i].ex,P[i].period);
}
getch();

我得到的输出是:

enter number of task
3
enter processname executiontime period

P[0] . process name=
P[0] . execution time =1
P[0] . period=2
P[1] . process name=
P[1] . execution time =3
P[1] . period=4
P[2] . process name=
P[2] . execution time =5
P[2] . period=6

processname executiontime period
1 2
3 4
5 6

发生了什么——为什么它不等待进程名称?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com