Solved

Writing struct to the file

Posted on 2000-03-05
2
285 Views
Last Modified: 2013-11-20
I tried to write and read the _RAL_ITEM
struct to file,but when read it,
the _RAL_ITEM struct from file contains
NULL data(such as strings...)
Here is definition:

typedef struct _TIME
{
      int iMin;
      int iHours;
      int iDay;
      int iMonth;
      int iYear;
};
typedef struct _RAL_ITEM
{
      int iIndex;
      UINT nType;
      CString sComment;
      CString sData      ;            
      _TIME time;
      BOOL bStopped;
      BOOL bDone;
};

I tried to write it to file this way:
 f.Write((void*)&item,sizeof(item));
-where f is opened file for writing
 and item is filled struct.

And read it this way:
 _RAL_ITEM item;
 f.Read((void*)&item,sizeof(item));
- where f is opened file for reading.
- after reading item.sData or
  item.sComment are empty(all data from
  struct are empty!!!

How to read it!!!
0
Comment
Question by:radek_s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 200 total points
ID: 2584830
Your problem is that sComment and sData are CStrings and cannot be used in this way - you must either use archiving (CArchive) or replace sComment and sData
with fixed length char arrays

typedef struct _RAL_ITEM
{
int iIndex;
UINT nType;
char sComment[32]; // you decide the max length required for this field
char sData[128] ; // you decide the max length required here also
_TIME time;
BOOL bStopped;
BOOL bDone;
};

you can then use the methods you have described

0
 

Author Comment

by:radek_s
ID: 2585529
Adjusted points to 200
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 129
notReplace  challenge 53 151
Bartender label printing - switch on and off graphics 3 73
moto 4g phone enable finger print 4 46
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question