sagar474
Full Member level 5

- Joined
- Oct 18, 2009
- Messages
- 285
- Helped
- 5
- Reputation
- 10
- Reaction score
- 5
- Trophy points
- 1,318
- Location
- India,kakinada
- Activity points
- 3,123
bindery file read error
I wrote the following code to read bmp file and write it to new bmp file
that is, to create a duplicate the bmp file.
but the created bmp file is not in correct format
when opened shows an error "this is not valid bmp file"
I wrote the following code to read bmp file and write it to new bmp file
that is, to create a duplicate the bmp file.
but the created bmp file is not in correct format
when opened shows an error "this is not valid bmp file"
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct BITMAPFILEHEADER{
unsigned short type;
unsigned long size;
unsigned short reserved1;
unsigned short reserved2;
unsigned long offsetbits;
};
struct BITMAPINFOHEADER{
unsigned long size;
unsigned long width;
unsigned long height;
unsigned short planes;
unsigned short bitcount;
unsigned long compression;
unsigned long sizeimage;
long xpelspermeter;
long ypelspermeter;
unsigned long colorsused;
unsigned long colorsimportant;
};
struct SINGLE_PIXEL{
unsigned char blue;
unsigned char green;
unsigned char red;
};
int i=0;
int S=0;
struct BITMAPFILEHEADER source_head;
struct BITMAPINFOHEADER source_info;
struct SINGLE_PIXEL source_pix;
struct head dist_head;
struct BITMAPINFOHEADER dist_info;
struct SINGLE_PIXEL dist_pix;
FILE *fp;
FILE *Dfp;
fp=fopen("rajni.bmp","rb");
Dfp=fopen("rajni2.bmp","wb");
fread(&source_head,sizeof(struct head),1,fp);
fread(&source_info,sizeof(struct BITMAPINFOHEADER),1,fp);
fwrite(&source_head,sizeof(struct head),1,Dfp);
fwrite(&source_info,sizeof(struct BITMAPINFOHEADER),1,Dfp);
S=source_info.width*source_info.height;
for(i=1;i<=S;i++)
{
fread(&source_pix,sizeof(struct SINGLE_PIXEL),1,fp);
fwrite(&source_pix,sizeof(struct SINGLE_PIXEL),1,Dfp);
}
fclose(fp);
fclose(Dfp);
return 0;
}