Thread: Structures and file io

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    6

    Thumbs up Structures and file io

    ok, i am trying to figure out how to use structs with file i/o. i am not quite sure if i am going in the right direction. i am writing a program that records any user defined files, their modify time, access time, and size. i decided to use a struct like:

    typedef struct FRec //Do i even need typedef?
    {
    char *iofilename;
    char *ioaccesstime;
    char *iomodsize;
    char *iosize;
    }Rec1;

    i can already get the info into the struct but i am having trouble writing it to a file. also reading from a file. my file format consists of:

    filename
    access time
    modify time
    size
    ...
    could someone help a downed C programmer?
    -mung

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Like so
    Code:
    fprintf( fp, "%s\n", Rec1.iofilename );
    Same sort of idea if you're using binary files and fwrite - you have to write what each pointer points to, not the pointer itself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Filling Array Of Structures From A File
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 11-26-2008, 09:59 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Replies: 3
    Last Post: 11-14-2005, 08:03 AM
  4. multiple file loading. so fruturated! help!
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 05:13 PM
  5. Printing a list of structures from a binary file
    By Emrys in forum C Programming
    Replies: 9
    Last Post: 05-12-2003, 01:45 PM