| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Structures |
G'Day Keith,
-=> Quoting Keith Fowler to All <=-
KF> Hello everyone, could some body please help me.. I'm trying to
KF> write a structure to a file, but i can't get it.. i've tried commands
KF> like WRITE, FWRITE, FPUTS, PUTC , PUTS etc etc.. but can't get it to
KF> go.. I think my structures right, here it is:
KF> typedef unsigned byte char;
The compiler may not like this line, but i do :-)
It's not needed anyway..
KF> STRUCT names {
KF> byte firstname;
KF> byte lastname;
KF> };
KF> STRUCT names writenames;
KF> Will that work?? :-).. any help would be appreciated..
Don't see struct in upper case too often, dunno if it'll compile like that.
Oh, and a name into a byte just won't go :-)
struct names{
char firstname[20];
char lastname [20];
};
struct names writenames;
int rite_names()
{
FILE *outfile;
outfile = fopen("namefile.dat","wb"); /* make sure
it's opened binary!! */
if(NULL == outfile) return FALSE;
fwrite(writenames,sizeof(struct names),1,out);
fclose (out);
return TRUE;
}
To read open the file with "rb", and using fread() with the same
parameters
what fwrite() used should work just fine.
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 78/0 620/243 623/630 632/349 635/503 544 727 711/401 409 410 SEEN-BY: 711/413 430 808 809 932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 635/544 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.