i have to copy a bitmap image file using a buffer. here is an example of what i need to do. i have to read different parts of a bitmap into the buffer first at once and then write it to the target file. when i read different parts into the buffer , the previous string gets overwritten and the last string that is read is only written. i dont want to use read and write function for every part that has to be written. please help me with the code.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
void fskip(FILE *fp, int num_bytes) {
int i;
for (i = 0; i < num_bytes; i++)
fgetc(fp);
}
int main() {
FILE *fp, *fp1;
fp = fopen("c:\\users\\tapan\\desktop\\splash.bmp", "rb");
fp1 = fopen("c:\\users\\tapan\\desktop\\splash2.bmp", "wb");
int *j;
j = (int *)malloc(3000);
int k = 223121;
int *i = &k;
fread(j, 2, 1, fp);
fread(j, 10, 1, fp);
fwrite(j, 12, 1, fp1);
fclose(fp1);
fclose(fp);
getch();
}
freadwrites to your buffer, but then the secondfreadalso writes to that buffer, overwriting the originalfreadcontents.