[ back to toc ]

data strutures and pointers - C programming

Date: 2002/03/29 15:35

Senario:Every time a copy of a magazine is sold, the program updates the records.
The updated records are then written back to stock_file and the computer
is switched off.

/* here is my struct*/

struct NewsRecord{ int code;
char title[TitleLength];
char month[10];
int numordered;
int numsold;
float wholeprice;
float retailprice;

I am new to C programming, so I need all the help I can get.

How do I update the records in the stock_file each morning?

How do I allocate enough memory using malloc?

Any help will be much appreciated.

I am using Visual C++ as my compiler.

Your questions are so basic and so general that I rather advioce you that
you read the documentation of the function malloc and do learn programming
in C.

You should pass the size of the memory you want to allocate to malloc,
thus in your case

malloc(sizeof(struct NewRecord));

To alter the file you have top open it using the function
fopen("file","r+"), fseek to the position where the record is and write
the file with the new content.


[ back to toc ]