#include <stdio.h>
#include <windows.h>
#include <string.h>
#define sprintfc(string, ...) sprintf(string+strlen(string), ##__VA_ARGS__)
///////////////////////////////////////////
int size(char *filename){
FILE*pFile=fopen(filename,"rb");
long lSize;
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
fclose(pFile);
return lSize;
}
///////////////////////////////////////////
char *el="lol.bmp";
int f=size(el);
long x = f*5+1;
char *res=(char*) malloc(x*5);
///////////////////////////////////////////
char* filehex(char *file2, char *mode)
{
int i;
int e=1;
long er=size(file2);
FILE*file=fopen(file2,mode);
memset(res,0,x*5);
printf("File Size: %d\n\n",er);
while((i=getc(file))!=EOF){
sprintfc(res,"0x%02x,",i);//The comma's and 0x are there because when i use BIN2C that's how its layed out
//so i thought it might make a difference
Sleep(1);
printf("\r%d of %d characters written",e,er);
e++;
}
res[strlen(res)-1] = 0;
}
///////////////////////////////////////////
int main(){
printf("\n%d\n",x); //<< What the malloc of res and as should be
printf("%d\n\n",strlen(res)); // Both printf out 4??
filehex(el, "rb");
char filename[] = "joy.txt";
FILE* dropped=fopen(filename,"wb+");
printf("\n%d\n",strlen(res));
fwrite(res,strlen(res),1,dropped);
fclose(dropped);
puts("Done");
free(res);
getchar();
return 0;
}