[英]Running a FIFO Simulation
I am trying to run a simulation program to test the FIFO algorithm, however my program is just crashing. 我试图运行一个仿真程序来测试FIFO算法,但是我的程序崩溃了。 this is the main, other functions not shown.
这是主要功能,其他功能未显示。 Can anyone spot for me the problem.Am not so familiar with using the main Argument[ int main(int argc, char *argv[])] I have the testing files in a folder
谁能为我发现问题。对使用主参数不太了解[int main(int argc,char * argv [])]我在文件夹中有测试文件
int main(int argc, char *argv[])
{
FILE *stream;
if (argc != 3)
{
printf("The format is: pager file_name memory_size.\n");
//exit(1);
}
printf("File used %s, resident set size %d\n", argv[1], atoi(argv[2]));
if ((stream = fopen(argv[1], "r")) == NULL)
{
perror("File open failed");
//exit(1);
}
mem_size = atoi(argv[2]);
start_simulation(stream);
fclose(stream);
system("pause");
}
Uncomment the calls to exit. 取消注释退出的注释。
if (argc != 3) {
// insufficient arguments passed..print error and exit.
printf("The format is: pager file_name memory_size.\n");
exit(1);
}
In your case (exit commented) if you don't provide command line arguments, argv[1]
will be NULL
and this can cause crash when used in fopen
在您的情况下(退出注释),如果不提供命令行参数,则
argv[1]
将为NULL
并且在fopen
使用时可能导致崩溃
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.