There's several problems with your code...
Code:
int count = 0, i = 0;
char z[count + 1];
This is the same as declaring char z[1], because count is 0 at the moment you declare z. And judging from your use of fgets and how you are indexing z further below, you want the z array to be of a much bigger size than just one element.
Code:
fin = fopen("cp1_ODEin.txt", "r");
fout = fopen("cp1_ODEout.txt", "w");
Not good because you move on to using fin and fout a few lines below this without ever checking if the files were actually opened. In case of failure, fin or fout will be null pointers and you'll get into trouble trying to use them. Instead you should guard against failure to open a file. And since opening both files seems essential for this code to work, you probably want just to abort in case of failure.:
Code:
#include <stdlib.h>
if ( (fin = fopen("cp1_ODEin.txt", "r")) == NULL ) {
fprintf(stderr, "Can't open file for reading. Aborting...\n");
exit(EXIT_FAILURE); // or return 1, on which case you don't need <stdlib.h>
}
if ( (fout = fopen("cp1_ODEout.txt", "w")) == NULL ) {
fclose(fin); // at this stage fin was opened. needs to be closed. see also notes below.
fprintf(stderr, "Can't open file for writing. Aborting...\n");
exit(EXIT_FAILURE); // or return 1, on which case you don't need <stdlib.h>
}
Next,
Not only is this unnecessary because count++ is the same as count = count + 1, so the assignment is superfluous, but more importantly it is undefined (and unspecified). C doesn't guarantee that the variable count will be incremented only after the assignment takes place. If count was equal to 1 before that statement, count can be 1 or 2 after it. There's no guarantee which. If you need to increment count just write count++; or count = count + 1;
Finally,
Not good. You are not closing the opened files, potentially leaking these two resources. Always close files that you have opened.
Code:
fclose(fin);
fclose(fout);
Even better than this is to check if the files were actually closed. There's very little you can do if for some reason you are not able to dispose of a resource opened by the same process that created it. But at least you can leave a message on the screen, since this is something your user should know about.
Code:
int disposed = fclose(fin) + fclose(fout); // fclose returns an int. 0 if successfully closed.
if (disposed != 0) {
fprintf(stderr, "error: could not close all files on exit.\n");
exit(EXIT_FAILURE); // or return 2, on which case you don't need <stdlib.h>
}