Ok so I decided to write some code to place a bunch of bitmap files into one FGD(fixed game data) file just for fire transfer's sake from a server to client update kinda deal I figured plain text would work great. This code though once we kick into the compression function decides to rename my filename variable say I pass in Slime.bmp I end up with S< at the end and a program crash. Anyone see something I am missing? Kinda late so maybe I am overlooking something simple...
Code:
#include <iostream>
#include <fstream>
#include <string.h>
#include <allegro.h>
#include <winalleg.h>
using namespace std;
void compress(char *);
ofstream FGD_FILE;
int main(int argc, char *argv[])
{
FGD_FILE.open("Compressed.fgd");
FGD_FILE<<argc-1<<endl;
if(!install_allegro(SYSTEM_NONE,&errno,atexit))
if(argc > 1)
{
for(int comp = 1;comp < argc;comp++)
{
compress(argv[comp]);
}
}else
{
cout<<"Files to compress are not specified."<<endl;
}
FGD_FILE.close();
return 0;
}
END_OF_MAIN(); //allegro specific to correct for winapi's main() function.
void compress(char *filename)
{
BITMAP *bmp;
RGB *palette;
char *isgoodfile = strstr(filename,".bmp");
if(isgoodfile != NULL)//non null if it is a bitmap or has .bmp in it at least.
{
bmp = load_bitmap(filename,palette);
//CHANGES THE NAME HERE
if (!bmp)
{
cout<<"Problem loading bitmap: "<<filename<<endl
<<"Compression aborted check file extention is a .bmp file"<<endl;
}else
{
int color_locked = -1; //technically valid for r=255 g=255 b=255 and a=255
int looped = 1;
FGD_FILE<<filename<<" "<<bmp->w<<" "<<bmp->h<<endl;
for(int y = 0;y < bmp->h;y++)
{
for(int x = 0;x < bmp->w;x++)
{
if(color_locked != getpixel(bmp,x,y))
{
if(color_locked != -1)FGD_FILE<<looped<<" "<<color_locked<<" ";
color_locked = getpixel(bmp,x,y);
looped = 1;
}else looped++;
}
}
FGD_FILE<<looped<<" "<<color_locked<<endl<<endl<<endl;
}
cout<<"Compressed and added file: "<<filename<<endl;
destroy_bitmap(bmp);
}else cout<<"Unable to verify file maybe it isn't a bitmap?"<<endl;
}