Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Subject : Reading structures from files !!!!!

RonaldsonRonaldson Member Posts: 42
To all reading this : It is important !!!!!

I am getting an error while reading structures from files: -

I am always getting errors while reading this structure

Output I get :

Instead of Shreaves Malfoy I get hreaves Malfoy. And Sometimes I get junk values. Is it because
I am using a large structure containing char strings of large size or is it because I am reading wrong from the files. However I am very sure that I am right in the way I deal with files. I use write and read functions of the fstream class
I am also facing similar problems with structure with just three members.

I have asked many people. Do you remember my White Pages telephone software I had made, I have problems with file handling. I have asked so many people but none have been able to come forward with a solution. I can even email you the code so that you can correct it. My email address is ronaldson40@asia.com


Why is that? Could you revert with a positive reply!

Best regards,
Ronaldson

[code]

I am giving the structure declaration

struct name
{
char name[25];
char city[25];
char country[25];
char occupation[25];
char in[25];
};
struct pass
{
long password;
long username;
};
struct tel
{
char fax[25];
char office[25];
char email[25];
char residence[25];
char pob[10];
};
struct dir
{
name n1;
pass p1;
tel t1;
};

[/code]

Comments

  • Bullet_09Bullet_09 Member Posts: 66
    I think it was because you wouldn't give out your code before.

  • ColdShineColdShine Member Posts: 597
    Your troubles might be due to data misalignment. What packing size are you using? The [b]dir[/b] data type could have padding bytes you didn't think there were, because of the [b]pass[/b] type probably being aligned on a 4-bytes boundary.
    Moreover, you should check the size of your text fields. My real name is a little longer than 25 chars... and I know people having way longer e-mail addresses, about 40 chars...
    ________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Your troubles might be due to data misalignment. What packing size are you using? The [b]dir[/b] data type could have padding bytes you didn't think there were, because of the [b]pass[/b] type probably being aligned on a 4-bytes boundary.
    : Moreover, you should check the size of your text fields. My real name is a little longer than 25 chars... and I know people having way longer e-mail addresses, about 40 chars...
    : ________________
    : [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]
    :
    :
    [blue]If you read/write your structures using 'sizeof()' all the time - the packing option does not matter. I am almost sure you missing symbols because the stream opened in text mode and not in binary mode.

    Also, just out of curiosity, why the 'password' is 'long' and not char[]?[/blue]
  • RonaldsonRonaldson Member Posts: 42
    Thanks a lot for your postive reply. If I want I could email my code. Its is about 3000 lines and is in c++ { I use Turbo c++ 3.0 for coding}
    Please provide me you email address. Your email address will be kept completely confidential
    [red][b][size=4]-:)Ronald[/b][/red][/size][blue]:-DSon[/blue]


  • Justin BibJustin Bib USAMember Posts: 0

    ______ // http://forcoder.org // free video tutorials and ebooks about || Scratch C++ MATLAB Java Python C Assembly Visual Basic .NET PL/SQL PHP Delphi C# Objective-C JavaScript R Ruby Go Perl Swift Visual Basic Transact-SQL Logo Rust Kotlin ML Erlang LabVIEW FoxPro Lisp Fortran Clojure SAS Scheme D Crystal Dart Apex F# COBOL Hack Prolog Ada Lua Awk Alice Bash Scala VBScript ABAP Julia || ______

Sign In or Register to comment.