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!

Print (1) variable of a structure definition after a read....? 1

Status
Not open for further replies.

johnfdutcher

Programmer
Dec 16, 2003
12
US
It looked easy in the book..
I read from a disk file into a structure:
structure rec_format {
char recnbr[3];
char regnbr[4];
char lname[15];
} rec;

fread(&rec, 1, 22, dsys); <---- dsys is an open fl ptr

then try to reference one variable in rec....

printf(&quot;The registration number is: %s&quot;,rec.regnbr);

The result prints the entire structure...not just the regnbr ??
 
That is what it is supposed to do. You have no null terminating byte. You can define %-3.3s to get the recnbr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top