简体   繁体   中英

Running a FIFO Simulation

I am trying to run a simulation program to test the FIFO algorithm, however my program is just crashing. 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[])
  {
   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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM