Thread: Need help with Project

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    41

    Post Need help with Project

    My sister want me to program a program to keep a inventory of her craft supplies, and she want me to have it so she can save her invertory, saveing in it's self is going to be a bear!

    I'm going to use Structues to for the invertory, I also need to make a menu too, most of this stuff I know how to do but saveing Structures! I don't know how to do that!

    So I'm looking for someone to help me on this project, email me if you want to help, my email is [email protected]

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    It's easy to write and read a structure from a file. Here are some examples.

    Code:
    #include <stdio.h>
    
    typedef struct{
     int data;
    } MYSTRUCT;
    
    void ReadData(char *file, MYSTRUCT *pstruc){
     FILE *f=fopen(file,"rb");
     fread(pstruc,sizeof(MYSTRUCT),1,f);
     fclose(f);
    }
    
    void SaveData(MYSTRUCT *pstruc, char *file){
     FILE *f=fopen(file,"wb");
     fwrite(pstruc,sizeof(MYSTRUCT),1,f);
     fclose(f);
    }
    
    int main(){
     MYSTRUCT ms;
     ms.data=1;
     SaveData(&ms,"mystruct.dat");
     ms.data=0; // zeroed to test reading function
     ReadData("mystruct.dat",&ms);
     printf("MyStruct's Data = %d\n",ms.data); // should be 1
     return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM