This is a Windows program, but the question I have is not Windows specific.
I have here a file encoder. You pass the file you want encoded into the file param and you're all set... in a perfect world. The problem is, I cannot get the program to stop writing when the file is done. It writes for the whole buffer size. this is the only way I could get it to work because I don't know how to get file size. Any ideas?
Oh yeah, it writes a byte to tell the decoder how to decode, just to note for you.
#define MyBufferLength 1024000
int WINAPI WinMain(HINSTANCE hInstance,
srand(time(NULL));//Randomize seed (based on computer clock time)
char mod = rand() % (3 - 25 + 2);//Random Modifier (key to the encoding)
char* FileBuffer = new char[MyBufferLength];//File read into this buffer
char* EncodedFile = new char;//Name for new encoded file
FILE *fd = fopen(lpCmdLine,"r+");
ModChar = mod;
if( fd == NULL )
MessageBox(HWND_DESKTOP,"Error opening file","Bah!",NULL);
for(int x = 0; x < MyBufferLength; x++)
FileBuffer[x] = FileBuffer[x] + mod;
fwrite(FileBuffer,sizeof(char),MyBufferLength/*needs to be length of file*/,fd);
You could write until feof() or read the position of the file with:
off_t fileLength = lseek(fd, 0L, SEEK_END);
Ah, thank you. What needs to be included to use that line of code?
not working... doesn't recognize identifiers.