Mrb, benm C de bmp dosyasını hex e çevirmem gerekiyor
#include <stdlib.h>
#include <stdio.h>
void extract(char *filename,char *img)
{
int byte = 0;
int start;
FILE *fp = fopen(filename,"rb"); //open file for reading
do fgetc(fp); while (++byte < 10);
fread(&start,4,1,fp);
byte += 4;
do fgetc(fp); while (++byte < start);
fread(img,1,9600,fp);
fclose(fp);
}
int main()
{
int i;
int j;
char hexdigit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
FILE *fp = fopen("outfile.c","w");
//unsigned char *bitmap = (unsigned char *)malloc(9600);
char *bitmap = (char *)malloc(9600); //assign 9600 bytes of memory to the pointer 'bitmap'
extract("desert.bmp",bitmap);
fputs("const unsigned char bitmap[] = \n{",fp);
for (i=239; i >= 0; i--) //start at bottom, and work up in rows
{
fputc('\n',fp); //each line, put a return
for (j = 0; j < 40; j++)
{
fputc('0',fp);
fputc('x',fp); //put the '0x' in front of the hex value
fputc(hexdigit[ (bitmap[(i*40)+j]>>4)&0x0F ],fp); //put the upper value of the byte
fputc(hexdigit[bitmap[(i*40)+j]&0x0F],fp); //put the lower value of the byte
if (!((i==1)&&(j==39))) fputc(',',fp);
}
}
fputs("\n}\n",fp);
fclose(fp);
free(bitmap);
getch();
}
bu program hex kodlarını yanlış veriyor bir hatam var hesaplamada galiba bilgisi olan biri cevaplarsa çok sevinirim...
#include <string.h>
string.h ı üstteki haliyle kodunun başına eklersen problem düzelebilir. Değişkenlerini tekrar kontrol edip ya da başta include ettiğin .h dosyalarının kodlarını da ekleyebilirsen neyin eksik olduğunu daha net söyleyebilirim sana elimden geldiğince. Verdiği hatayı da daha net anlamış oluruz sanırım. Bir de hex haline dönüştürmek istediğine göre bir işlemciyi programlamaya çalışıyorsun anladığım kadarıyla markasını modelini tarif edersen daha da açıklayıcı olmuş olur.