1

当我尝试打印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;
}
4

1 回答 1

3

阅读后newProcess->expectedRunTime,您将使用以下内容覆盖它:

fscanf(myInput, "%d", & (newProcess->expectedRunTime) );
(newProcess->expectedRunTime)=(newProcess->remainingRunTime);

其中有垃圾,因为没有写入任何内容newProcess->remainingRunTime

于 2012-12-24T16:51:42.443 回答