当我尝试打印expectedRuntime变量时,它会打印expectedRuntime的地址。 但我可以正确打印timeOfSubmission变量。有人可以帮帮我吗?
struct process
{
int timeOfSubmission;
int remainingRunTime;
int expectedRunTime;
char processName[20];
};
int main()
{
FILE *myInput;
myInput = fopen("input.txt", "r+");
while ( !feof(myInput) )
{
struct process * newProcess=(struct process *)malloc(sizeof(struct process));
fscanf(myInput, "%s", newProcess->processName);
fscanf(myInput, "%d", & (newProcess->expectedRunTime) );
(newProcess->expectedRunTime)=(newProcess->remainingRunTime);
fscanf(myInput, "%d", & (newProcess->timeOfSubmission) );
printf("%s ",newProcess->processName);
fflush(stdout);
printf("%d ",newProcess->expectedRunTime);
fflush(stdout);
printf("%d \n",newProcess->timeOfSubmission);
fflush(stdout);
}
return 0;
}
答案 0 :(得分:3)
阅读newProcess->expectedRunTime
后,
你用以下方法覆盖它:
fscanf(myInput, "%d", & (newProcess->expectedRunTime) );
(newProcess->expectedRunTime)=(newProcess->remainingRunTime);
有垃圾,因为没有写入newProcess->remainingRunTime
。