Hi, I'm in need of help getting my code to create a dynamic structure array based on the number of files. Here is the code.
Code:
#include <stdio.h>
struct Version
{
int major;
int minor;
int build;
int numFiles;
};
struct Download
{
char name[56];
char outName[16];
};
int main()
{
struct Version ver;
int j;
ver.major = 0;
ver.minor = 4;
ver.build = 2;
ver.numFiles = 1;
struct Download file[ver.numFiles];
file[0].name[] = "http://website.com/projects/dod/Files.rar";
file[0].outName[] = "Files.rar";
FILE *fp;
fp = fopen("version.dat", "wb");
fwrite(&ver, 1, sizeof(ver), fp);
fclose(fp);
ver.minor = 5;
fp = fopen("update.dat", "wb");
fwrite(&ver, 1, sizeof(ver), fp);
fwrite(&file, 1, sizeof(file), fp);
fclose(fp);
sleep(100);
fp = fopen("version.dat", "rb");
fread(&ver, sizeof(ver), 1, fp);
fclose(fp);
printf("Version.dat\n\nVersion %i.%i.%i Number of files %i\n\n", ver.major, ver.minor, ver.build, ver.numFiles);
fp = fopen("update.dat", "rb");
fread(&ver, sizeof(ver), 1, fp);
fread(&file[ver.numFiles], sizeof(file[ver.numFiles]), 1, fp);
fclose(fp);
printf("Update.dat\n\nVersion %i.%i.%i Number of files %i\n\n", ver.major, ver.minor, ver.build, ver.numFiles);
for(j = 0; j < ver.numFiles; j++)
printf("Name %s\nOutName %s\n\n", file[j].name, file[j].outName);
getchar();
return 0;
}
What this program (is suppose to) does is:
1. Creates a version.dat to contain the version information (numFiles is useless for this file)
2. Creates an updated.dat file to contain the new file version, the number of files needed to download, and finally the path to the file(s), and the outfilename(s).
3. Read in this data, and display it to the screen
Thanks for the help