Need help with Project

This is a discussion on Need help with Project within the C Programming forums, part of the General Programming Boards category; My sister want me to program a program to keep a inventory of her craft supplies, and she want me ...

  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 budgiekarl@cox.net

  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, 10:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02: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, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21