tags:

views:

39

answers:

1

I am trying to run a simulation program to test the FIFO alogarithm, howerver 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");
}
A: 

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 the your does not provide cmd-line arguments, argv[1] will be NULL and this can cause crash when used in fopen

codaddict
Well just noticed that the its not opening the file stream.if i un comment the exit(1), it exits imediately.
George William Mugume
Its exiting because you are not providing enough cmd-line args and that is what we want.
codaddict
Linux or Windows ?
codaddict
am using windows
George William Mugume
Dev compiler, is it possible to be a compiler problem. All the code seems fine
George William Mugume
Compile the program use the IDE and run it from the DOS prompt as: `C:\>prg.exe file_name mem_size` after you go to the dir that has the executable.
codaddict
Glad to know it worked. Good night. Also consider accepting answers which helped you resolve the issue since your accept rate is 0 !!!
codaddict