I think things would be easier for everyone, especially yourself, if you describe more clearly what you are supposed to do AND how it is, specifically in relation to what you wrote, that you intend to get it done.
For example, in your original post you mention "a new file is written with the new order". What new order? All you've said is that a line of cars drive onto one ferry, go somewhere, drive off, and get onto another ferry. Why would their order change? You also mention other details that may be important, but maybe not, such as "when boat is full or there's no car for Q left". Are any cars left seperate at some point? Are the ferries the same size? Since you claim your program doesn't work the way you want it too, there is not much point in trying to figure out what you wanted by looking at that, is there?
The first thing I noticed when I looked at as3b.c was this:
Code:
fpin=openFile(argv[3], "r");
[...]
FILE *openFile(char *filename, char *mode)
{
FILE *fp;
fp= fopen(filename, mode);
if (fp==NULL){
printf("Cannot open file: %s.\nExiting...\n", filename);
exit(1);
return NULL;
}
else{
return fp;
}
}
Why would you call exit, and then return??? What's suppose to happen here:
1) The program ends.
2) The function ends.
3) The function returns a NULL pointer.
It certainly won't be the last case, anyway. Do you see now how trying to deduce intentions from code you already know is flawed might be a waste of time?
This would be better, perhaps, as this (I'm guessing as to your intentions):
Code:
if ((fpin=openFile(argv[3], "r"))==NULL) {
printf("Cannot open file: %s.\nExiting...\n", argv[3]);
exit (1);
}
[...]
FILE *openFile(char *filename, char *mode)
{
FILE *fp;
fp= fopen(filename, mode);
}
Hmmm, looks like "openFile" is really just fopen! Maybe this would have been fine then:
Code:
if ((fpin=fopen(argv[3], "r"))==NULL) {
printf("Cannot open file: %s.\nExiting...\n", argv[3]);
exit (1);
}
My confidence in your ability to think, much less program a computer, is fading fast. How many other superfluous functions are in here? Before I go any further, you will have to answer my questions.