I have a function that will read a file of numbers and place them into an array. I need to create a new function that will, given that stored array, output the array to a new file.
This is the code I have:
Right now, it does not work. The fwrite function is suppose to return the number of copies (= Size, determined in other function -- that does work), but it is not copying all of the values. I'm unsure of how to do it.
This is the code I have:
Code:
int Save(char *File, long *Array, int Size) {
FILE *fp = fopen(File, "wb");
if (fp == NULL) { // check to see if file opens; if NULL, failed
printf("Error opening file. \n");
return 0;
}
if (fwrite(&Array, sizeof(int), 1, fp) != Size) {
printf("File write error.");
}
fclose(fp);
return (Size);
}
Comment