I have an array of long values and I would like to save them to a file called "Longs.myData". I expected my file to have a size of 24 bytes since the array only has 3 indices. However, I am getting a file that is 192 bytes. Is there a way to save my data and get a file that takes up 24 bytes? P.S I know that saving the file as a .txt gives a file size of 33 bytes. Thank you!
#include <stdio.h>
#include <stdlib.h>
void CreateFile()
{
//Array containing my data
long data[3];
data[0] = 2147483644;
data[1] = 2147483645;
data[2] = 2147483646;
//Initializing a pointer to FILE
FILE *myFilePointer;
//Creating a new file "Longs.myData"
myFilePointer = fopen("Longs.myData", "wb");
//Error handling
if(myFilePointer == NULL){exit(1);}
//Save array to file
fwrite(data, sizeof(long), sizeof(data), myFilePointer);
//sizeof(long) = 8, sizeof(data) = 24 //Total 192
printf("%d %d \n", (int) sizeof(long), (int) sizeof(data));
fclose(myFilePointer);
}
int main()
{
CreateFile();
return 0;
}