Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner Question 1

Status
Not open for further replies.

WillieBotha

Programmer
Jun 20, 2001
5
ZA
Hi,

I am a beginner in C++ and Writing Dat file headers and info. I have to change some of the coding now but I have to know what it exactly does ?

Thanks a lot !

int MMWriteHdr_UserName(FILE* fp, char* username)
{
short len=strlen(username)+1;
char* cp = username;

MMBufCrypt((unsigned char*)cp, len-1);

if (len<=MAX_USERNAME_LEN)
{
if (!fseek(fp, 0L, SEEK_SET))
if (fwrite(&len, sizeof(short), 1, fp))
return fwrite(cp, sizeof(char), len, fp);
}

return 0;
}

int MMWriteHdr(FILE* fp, struct sHdr* pHdr)
{
if (!MMWriteHdr_UserName(fp, pHdr->UserName))
return 0;

if (!fseek(fp, OFF_RELMONTH, SEEK_SET))
{
fwrite(&pHdr->dbRelMonth, sizeof(short), 1, fp);
fwrite(&pHdr->dbRelYear, sizeof(short), 1, fp);
fwrite(&pHdr->dbRelRevision, sizeof(short), 1, fp);

fwrite(&pHdr->nMakeTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oMakeTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nModelTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oModelTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nVariantTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oVariantTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nPriceTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oPriceTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nMileageTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oMileageTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nConditionTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oConditionTbl, sizeof(long), 1, fp);

fwrite(&pHdr->nOptionTbl, sizeof(short), 1, fp);
fwrite(&pHdr->oOptionTbl, sizeof(long), 1, fp);

return 1;
}

return 0;
} Willie Botha
Programmer
Mead & McGrouther
South-Africa
 
you're functions are merely c-functions. there's nothing of c++ to it.
you should specify what you don't understand in it.
Maybe you're unfamiliar with '->'. that's simply accessing a structure-component with a pointer to the structure.
fseek(..) and fwrite(..) you'll find in any c-documentation.
 
Well all I actually want to know in the first function - is he writing something before the username in :
if (!fseek(fp, 0L, SEEK_SET))
-->(here): if (fwrite(&len, sizeof(short), 1, fp))
return fwrite(cp, sizeof(char), len, fp);

and if you use all the fwrite statements after each other does that mean that these values are written next to each other (No spaces in between).

Sorry for asking dumb questions like this.

Thanks i advance,
Willie Botha
Programmer
Mead & McGrouther
South-Africa
 
it writes the length of username as first byte.
e.g. PASCAL doesn't use a character to determine the length of a string. it rather writes the length to byte 0.
with the other data, there shouldn't be space or any other
seperator inbetween.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top