This puts out a file with an invaild name. I cant see the problem. Can you help?
Code:
#include <iostream>
#include <fstream>
using namespace std;
int hednspos();
int hednepos(int);
char * hedname(int, int);
long filesiz(int);
long fileoff(int);
char * filecont(long, long);
int writefile(char *, char *, long);
int main()
{
long size, offset;
char * Data;
char * name;
char * content;
int namespos, nameepos;
namespos = hednspos();
cout << "File Name Start Pos: " << namespos;
nameepos = hednepos(namespos);
cout << "\nFile Name End Pos: " << nameepos;
name = hedname(namespos, nameepos);
cout << "\nFile Name: " << name;
size = filesiz(namespos);
cout << "\nFile Size: " << size;
offset = fileoff(namespos);
cout << "\nFile Offset: " << offset;
content = filecont(offset, size);
writefile(content, name, size);
return 0;
}
int hednspos()
{
int namestart;
char ptn1;
ifstream hed("datap.hed", ios::in | ios::binary);
while(ptn1 != 92)
{
hed.read(&ptn1, 1);
if(ptn1 == 92)
{
namestart = hed.tellg();
}
}
hed.close();
return namestart;
}
int hednepos(int pnt1)
{
char ch = 92;
int nameend;
ifstream hed("datap.hed", ios::in | ios::binary);
hed.seekg(pnt1);
while(ch != 0)
{
hed.read(&ch, 1);
if(ch == 0)
{
nameend = hed.tellg();
}
}
hed.close();
return nameend;
}
char * hedname(int names, int namee)
{
int size = (names + namee);
char ch;
char name[size];
int x = 0;
ifstream hed("datap.hed", ios::in | ios::binary);
hed.seekg(names-1);
while(ch != 0)
{
hed.read(&ch, 1);
name[x] = ch;
x++;
if(ch == 92)
{
x = 0;
}
}
hed.close();
return name;
}
long filesiz(int pos)
{
long size;
ifstream hed("datap.hed", ios::in | ios::binary);
hed.seekg(pos-5);
hed.read(reinterpret_cast<char*>(&size),4);
hed.close();
return size;
}
long fileoff(int pos)
{
long offset;
ifstream hed("datap.hed", ios::in | ios::binary);
hed.seekg(pos-9);
hed.read(reinterpret_cast<char*>(&offset),4);
hed.close();
return offset;
}
char * filecont(long offset, long size)
{
char * content;
ifstream hed("datap.wad", ios::in | ios::binary);
hed.seekg(offset);
content = new char[size];
hed.read(content,size);
hed.close();
return content;
}
int writefile(char * content, char * name, long size)
{
ofstream file(name, ios::out | ios::binary);
file.write(content, size);
file.close();
return 0;
}
It outputs this
Code:
File Name Start Pos: 9
File Name End Pos: 32
File Name: standardkeyq.bin
File Size: 2048
File Offset: 0
and the name of the file is
Code:
????????????)??????? ???<????????????????????p??? (invalid encoding)
weird, and yes i know my brackets are out of place, thats just the way my compiler has them.