Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Reading data from files

Reply
Thread Tools

Reading data from files

 
 
krishna_v
Guest
Posts: n/a
 
      07-25-2003

How to read data from files to structures(structure having more
elements)
Thanks in adavance

--
Posted via http://dbforums.com
 
Reply With Quote
 
 
 
 
krishna_v
Guest
Posts: n/a
 
      08-12-2003

Originally posted by Burne C
> "krishna_v" wrote in message news:3150950.1059105697@dbforums.-
> comnews:(E-Mail Removed)...
> > How to read data from files to structures(structure having

> more
> > elements)
> > Thanks in adavance
> > --
> > Posted via

> http://dbforums.com/http://dbforums.com
>
> If you write the structure to the file by yourself and you have to
> read it later (on the same
> machine), try this method :
>
> #include
>
> /* some structure */
> typedef struct mystruct_tag
> {
> int var1;
> int var2;
> long var3;
> }mystruct;
>
> int main(void)
> {
> /* create a file */
> FILE *fp = tmpfile();
> mystruct mst1;
> mystruct mst2 = {10,20,30};
>
> /* write the structure */
> fwrite(&mst2,sizeof(mystruct),1,fp);
>
> rewind(fp);
>
> /* try to read it back */
> fread(&mst1,sizeof(mystruct),1,fp);
>
> printf("The struct contain %d %d %d
> \n",mst1.var1,mst1.var2,mst1.var3);
>
> fclose(fp);
>
> return 0;
>

}

--
Posted via http://dbforums.com
 
Reply With Quote
 
 
 
 
krishna_v
Guest
Posts: n/a
 
      08-12-2003

Originally posted by Zoran Cutura
> krishna_v wrote:
> >
> > How to read data from files to structures(structure having

> more
> > elements)

>
> That pretty much depends on how the data is stored into the
> file, which
> is what people call file formats.
> Note that structures cannot be portable written and read from a file
> as blocks, because they may include system dependent stuff like
> padding
> bytes. So if you're talking about structure data that is written to a
> file in binary as a block, you'll probably burn your fingers.
> Store every element of the structure as a value of its own and read it
> back is this.
>
>
> --
> Z ((E-Mail Removed))
> "LISP is worth learning for the profound enlightenment experience
> you will have when you finally get it; that experience will make you
> a better programmer for the rest of your days." -- Eric S. Raymond
>


HI
Thank you.

--
Posted via http://dbforums.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading files inside zip files from Javascript Narendra Sisodiya Javascript 7 12-08-2009 02:15 AM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
JAR files reading list files rob hadow Java 4 05-21-2004 04:41 PM
Reading/writing data to/from files into 2D array Modukuri VHDL 0 05-19-2004 04:03 PM
Reading data out from different files Mario Fischer Perl 0 10-15-2003 11:59 AM



Advertisments