All pastes #674552 Raw Edit

Mine

public text v1 · immutable
#674552 ·published 2007-08-29 10:41 UTC
rendered paste body
#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);
return lSize;
}
///////////////////////////////////////////
int f=size("lol.bmp");
int x = f*5+1;
char*as=(char*) malloc (x);
char *res=(char*) malloc(x);
///////////////////////////////////////////
char* filehex(char *file2, char *mode)
{
 int i;
 int e=1;
 int er=size(file2);
 FILE*file=fopen(file2,mode);
 memset(as,0,er*5+1);
 memset(res,0,er*5+1);
 printf("%d\n\n",er); 
while((i=getc(file))!=EOF){
sprintfc(as,"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++;
}

 strncat(res,as,er-1);
 free(as);
}
///////////////////////////////////////////
int main(){
    char *el="lol.bmp";
    char filename[] = "joy.txt";
    FILE* dropped=fopen(filename,"wb");
    
    printf("\n%d\n",x); //<< What the malloc of res and as should be
    printf("%d\n",sizeof(as)); // Both printf out 4??
    printf("%d\n\n",sizeof(res)); // Both printf out 4??
    filehex(el, "rb");
    printf("\n%d\n",sizeof(as)); //Just to see if there was a difference...
    printf("%d\n",sizeof(res));

    fwrite(res,sizeof(res),1,dropped); 
    fclose(dropped);
    puts("Done");
    free(res);
    getchar();
return 0;
}