473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Stream and Reader help

mag
Let's start off by saying I'm a noob to .Net but here's my problem.
I have many files, all with the same structure.
I know the structure, It was written in some version of C++.
Because it seem to be a null terminated or serialized file
structure.....
using text readers reads only until the first null and thinks it has
reached the EOF.
Using the BinaryReader and the BaseStream.Position I know where I'm at
in the file. However, most of the file is numeric and presenting no
dificulties, but one field is text and I cannot get it to display in a
Datagrid other than numeric. The numeric values of the text field do
not corrolate to ansi, ascii, or anything else I can determine.
Here is a small sampling of the code that wrote the file:
in.open(filename, ios::binary);
if (in.fail())
return false;
in.read((char*)&Version, sizeof(unsigned int));
if (Version != DB_VERSION) { // fixme
in.close();
return false;
}
Id << in;
in.read((char*)&totalX, sizeof(unsigned int));
in.read((char*)&totalY, sizeof(unsigned int));
in.read((char*)&totalZ, sizeof(unsigned int));
in.read((char*)&total1, sizeof(unsigned int));
through position 580 then the text part is added
const bool Namespace::Write(const char* path, const char* name)
{
const unsigned int currentVersion = DB_VERSION;
ofstream out;
ifstream in;
char filename[MAX_PATH + MAX_ID_STRING+1];
int i, j, n;
char namesUsed[3][MAX_NAME+1];
unsigned int nameCount[3];
bool done, newFile;
int mostIdx[3] = {-1,-1,-1};
unsigned int topNum;
int topIdx;
unsigned int Version;
n = (unsigned)strlen(path);
if (n > MAX_PATH)
n = MAX_PATH;
strncpy(filename, path, n);
steamId.ToStr(filename + n);
strcat(filename, ".some extension");
// replace ':' with '-' in filename
for (i=n, n=strlen(filename); i < n; i++) {
if (filename[i] == ':')
filename[i] = '-';
}
// Read file and store the namesUsed and nameCount variables
in.open(filename, ios::binary);
newFile = (in.fail() || in.peek() == EOF);
for(i=0; i<3; i++) {
namesUsed[i][0] = 0;
nameCount[i] = 0;
}
Any Help would be Greatly appreciated. I have been working on this
issue for two weeks, using many google searches and samples.
Thanks

Nov 19 '05 #1
2 1928
On 16 Jun 2005 18:00:56 -0700, "mag" <mg****@nicheware-inc.com> wrote:

It's been quite some time since I've done C++, but I dont see where
the ofstream is used at all. There are too many gaps in the code to
make sense of it all.

--
Scott
http://www.OdeToCode.com/blogs/scott/

<snip>


const bool Namespace::Write(const char* path, const char* name)
{
const unsigned int currentVersion = DB_VERSION;
ofstream out;
ifstream in;
char filename[MAX_PATH + MAX_ID_STRING+1];
int i, j, n;
char namesUsed[3][MAX_NAME+1];
unsigned int nameCount[3];
bool done, newFile;
int mostIdx[3] = {-1,-1,-1};
unsigned int topNum;
int topIdx;
unsigned int Version;
n = (unsigned)strlen(path);
if (n > MAX_PATH)
n = MAX_PATH;
strncpy(filename, path, n);
steamId.ToStr(filename + n);
strcat(filename, ".some extension");
// replace ':' with '-' in filename
for (i=n, n=strlen(filename); i < n; i++) {
if (filename[i] == ':')
filename[i] = '-';
}
// Read file and store the namesUsed and nameCount variables
in.open(filename, ios::binary);
newFile = (in.fail() || in.peek() == EOF);
for(i=0; i<3; i++) {
namesUsed[i][0] = 0;
nameCount[i] = 0;
}


Nov 19 '05 #2
mag
Thanks Scott for the reply,
The Out.write is exactly as the in.read.
Looking at the file with notepad, it's just a bunch of garbage
characters then a text string (human readable). That human readable
part is at postion in basestream of 584. 584 = number of integer
fields times size of integer (4) or position 584/4=148 -1 for zero
base. It's at that piont I cannont get anything to read the ascii
characters.
Using the binary reader gets me past all the null terminated field
serparators, but a text or byte or char read gets stopped at the first
null piont thinking it's at the end of the file.
Hence my problem.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Amey Samant | last post by:
hi all i was trying to read an integer from keyboard with DataInputStream can someone explain the behaviour of the following code ???? <code> DataInputStream dis=new...
4
by: Leon Jollans | last post by:
Hi. I'm reading a 5 meg (or so) file from the response stream of a WebRequest, and it's pitifully slow. I mean *really* slow, in the order of 15 minutes to download. Now obviously I'm caching this...
1
by: John | last post by:
I have a Socket open to a target system. I get the network stream from the open socket and then create a stream reader and stream writer on this stream. The stream reader and writers are operating...
6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
14
by: Laszlo Szijarto | last post by:
Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory stream or even file stream in big endian order or do I have to write something custom to reverse the byte order? So, for...
8
by: Scott | last post by:
Hi guys, If I try to call read(), readline(), readtoend() and there is nothing to read (from a never ending loop for example) the program seems to continue but it exits the loop for no apparent...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
3
by: Martin Z | last post by:
Hi, I have an application that involves sending a lot of XML data to various places. The problem is that once in a while, I just want the XML document as a string (for example, sending to a...
2
by: Jack | last post by:
Hi, I want to read a string a chars from a stream, and put it into a string. At the moment, I'm creating a buffer of a fixed size, and reading the stream of text into it. It works, but I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.