Thanks again, Salem. I inserted this into the code and now it runs fine:
Code:
char * PrependPath(char * filename, const char * argv0)
{
char temp[strlen(filename)+1];
strcpy(temp, filename);
strcpy(filename, argv0);
char * next = filename, * end = filename;
do{
next = strstr(next, "\\");
if(next)end = ++next;
}while(next);
*end = 0;
strcat(filename, temp);
return filename;
}
#include <iostream>
#include <stdio.h>
int main(int argc, char *argv[])
{
char file[10240] = "x.dat";
PrependPath(file, *argv);
int a = 123;
int b = 456;
cout << "a: " << a << endl;
cout << "b: " << b << endl << endl;
FILE * fp = fopen(file, "rb");
if(fp)
{
fread(&a, sizeof(int), 1, fp);
fread(&b, sizeof(int), 1, fp);
fclose(fp);
}
else
{
fp = fopen(file, "wb");
if(fp)
{
fwrite(&a, sizeof(int), 1, fp);
fwrite(&b, sizeof(int), 1, fp);
fclose(fp);
}
}
cout << "a: " << a << endl;
cout << "b: " << b << endl;
cin.get();
return 0;
}
I appreciate your help!!