At the moment, I'm stuck with this code.
Code:
/******************* PREPROCESSOR DIRECTIVES *************************
*/
/******** HEADER FILES ****
*/
#include <conio.h> /* Console I/O Header */
#include <stdio.h> /* Standard I/O Header */
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dos.h>
#include <time.h>
/**** NAMED CONSTANTS ***
*/
#define filename "c:\\stock.dat" /* Name of the data file on the disk */
/********** USER-DEFINED AND ENUMERATED DATA TYPES *******************
*/
struct stock_struct // User-Defined data structure
{
char Product_Group_Code[20];
char Product_Code[15];
char Description[32];
int Stock_Level;
} ;
/******************* FUNCTION PROTOTYPES *****************************
*/
Mainmenu();
Flushkeyboardbuffer();
Create();
Addproducts();
Reload();
Displayoptions();
Saleofproducts();
void writeinfo(FILE*, struct stock_struct stock);
struct stock_struct getinfo();
/********************* GLOBAL VARIABLES ******************************
*/
char Selection;
/******************** MAIN FUNCTION **********************************
*/
void main ()
{
clrscr();
Mainmenu();
}
/******************** OTHER FUNCTIONS ********************************
*/
void Mainmenu ()
{
/* Keep at this screen till Selection is chosen */
do
{
clrscr();
/* Choices Selection */
gotoxy(25,4); textcolor(15); cprintf("Stock Control System");
gotoxy(22,6); textcolor(15); cprintf("Please select from the following options:");
gotoxy(25,8); textcolor(12); cprintf("1. Create initial database");
gotoxy(25,10); textcolor(YELLOW); cprintf("2. Add details of new products");
gotoxy(25,12); textcolor(12); cprintf("3. Reload the System");
gotoxy(25,14); textcolor(YELLOW); cprintf("4. Display Options");
gotoxy(25,16); textcolor(12); cprintf("5. Sale of products by product description");
gotoxy(25,24); textcolor(2); cprintf("Please Make A Selection");
Selection = getch();
printf("%c", Selection);
getch();
Flushkeyboardbuffer();
if (Selection == '1')
{
Create(); /* Go to One Element Module */
}
else
if (Selection == '2')
{
Addproducts(); /* Go to Two Element Module */
}
else
if (Selection == '3')
{
Reload(); /* Go to Two Element Module */
}
else
if (Selection == '4')
{
Displayoptions(); /* Go to Two Element Module */
}
else
if (Selection == '5')
{
Saleofproducts(); /* Go to Two Element Module */
}
} while(!(Selection >= '1' && Selection <= '6'));
}
void Flushkeyboardbuffer()
{
while (kbhit()) getch(); /* Read and get rid of any previous keystrokes left in memory */
}
void Addproducts()
{
struct stock_struct stockrec;
FILE *stockfile;
stockfile = fopen(filename, "a"); // The stockfile is linked to disk, then opened for append
stockrec = getinfo(); // Call function: Get's data from keyboard
writeinfo(stockfile, stockrec); // call function that writes to file
fclose(stockfile); // Closes stockfile
}
struct stock_struct getinfo()
{
struct stock_struct stock; // Used to store input data
int arrayindex;
int strpos;
char temp;
clrscr();
gotoxy(10,2); textcolor(14); cprintf("Enter Details as follows: ");
gotoxy(14,4); textcolor(14); cprintf("Product Group Code: ");
gotoxy(40,4); gets(stock.Product_Group_Code);
gotoxy(14,6); textcolor(14); cprintf("Product Code: ");
gotoxy(40,6); gets(stock.Product_Code);
gotoxy(14,8); textcolor(14); cprintf("Description: ");
gotoxy(40,8); gets(stock.Description);
gotoxy(14,10); textcolor(14); cprintf("Stock Level: ");
gotoxy(40,10); gets(stock.Stock_Level);
return stock; // Data returned to module
}
void writeinfo(FILE *file_handle, stock_struct stock)
{
fwrite(&stock, sizeof(stock), 1, file_handle);
}
I'm trying to get addproducts to write the input from the keyboard and place it into the file. I'm completely stumped at the moment though, and I keep getting type mismatch errors in TurboC++. Any help would be appreciated.