i dont know if this is wright so help me please...thnks for advance

inside my inventory.ini

000001,hamburger,30.50
000002,cheeseburger,21.00
100001,frenchfries,21.00
200001,icedtea,17.00

try to run it..

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

#define ERROR -1
#define OK 0

#define TRUE 1
#define FALSE 0

/* error codes */
#define ERR_INVALID 1
#define ERR_CODE_NOT_EXIST 2

#define LEN_INV_CODE 6
#define LEN_INV_NAME 10

typedef struct Inventory 
{
	char strName[LEN_INV_NAME+1]; /*product description*/
	char strCode[LEN_INV_CODE+1]; /*product code*/
	float fPrice;                 /*price*/
	int nQty;                     /*quantity sold for each purchase*/
} InventoryInfo;

struct Inventory* product;        /*inventory array*/
int numOfRec = 0;                 /*number of records*/
int nReceiptNum = 0;              /*receipt number*/
FILE* fileIni;                    /*initialization file*/
FILE* fileReceipt;                /*receipt file*/

void takeOrder();
int initializeInventory();
void resetQuantity();
void printReceipt();
void error(int errType);
int searchInventory(const char* str);
int countRecords();
int isBlankString(const char* strBuffer);

int main()
{
	char strChoice[10];
	
	if (initializeInventory() == ERROR)
	{
		printf("File does not exist.\n");
		system("pause");
		return ERROR;
	}
	
	do
	{
		system("cls");
		memset(strChoice, '\0', 10);
		printf("-----Main Menu-----\n");
		printf("[1] Accept Purchase\n");
		printf("[0] Exit System\n\n");
		printf("Enter Menu: ");
		gets(strChoice);
		
		switch(strChoice[0])
		{
			case '1':
				system("cls");
				printf("-----Accept Purchase-----\n");
				takeOrder();
				break;
			case '0':
				break;
			default:
				error(ERR_INVALID);
				getch();
		}
	}while (strChoice[0] != '0');
	
	free(product);
	return 1;
}

/*****************************
count the number of records in the initialization file 
returns -1 if error occurs; otherwise returns the number of records
*****************************/
int countRecords()
{
	char strTemp[30];
	int nCount = 0;
	FILE* fileInventory;
	
	fileInventory = fopen("inventory.ini", "rt");
	if (fileInventory == NULL)
	{
		return ERROR;
	}
	/* count the number of records */
	while (!feof(fileInventory))
	{
		fscanf(fileInventory, "%[^\n]\n", strTemp);
		nCount++;
	}
	fclose(fileInventory);
	return nCount;
}

/**********************************
initializes the inventory array 
returns  -1 if error occurs; otherwise returns 0
**********************************/
int initializeInventory()
{
	int i;
	char temp[30];
	int nRet = 0;
	nRet = countRecords();
	
	if (nRet == ERROR)
	{
		return ERROR;
	}
	numOfRec = nRet;
	
	/* dynamically allocates inventory array */
	product = (struct Inventory*)
		malloc(numOfRec * sizeof(struct Inventory));
		
	fileIni=fopen("inventory.ini", "r");
	
	for(i=0; i<numOfRec; i++)
	{
	/*supply missing*/
	}
	fclose(fileIni);
	return OK;
}

/***********************************
take orders from user
***********************************/
void takeOrder()


{
	char strChoice[7];
	/*supply missing*/
	int nHasPurchase;
	
	/*supply missing*/
	resetQuantity();
	
	nHasPurchase = FALSE;
	
	printf("Enter Code: ");
	gets(strChoice);
	
	nHasPurchase = TRUE;
	
	if (nHasPurchase == TRUE)
	{
		printReceipt();
	}
}

/****************************************
reset all quantity to zero for the next purchase
****************************************/
void resetQuantity()
{
	int i;
	for(i=0; i<numOfRec; i++)
	{
		product[i].nQty = 0;
	}
}

/****************************************
prints the receipt onto scree and writes it to file
****************************************/
void printReceipt()
{
	system("cls");
	
	printf("-----Official Receipt-----\n");
	printf("Robii's Fastfood \n");
	printf("OR Number: %d\n\n", nReceiptNum);
	printf("Item      Qty       Price");
	printf("\n\n\n");
	system("pause");
}

/*****************************************
print error messages
*****************************************/
void error(int nErrorType)
{
	switch(nErrorType)
	{
		case ERR_INVALID:
			printf("Invalid Input.\n");
			break;
		case ERR_CODE_NOT_EXIST:
			printf("<<Code does not exist>>\n");
			break;
	}
}

/*******************************************
search an inventory and return its index
*******************************************/
int searchInventory(const char* str)
{
	return ERROR;
}

int isBlankString(const char* strBuffer)
{
	return TRUE;
}

Recommended Answers

All 2 Replies

No problem with your code.Its running fine.
But you are not sure what you want
1)The inventory.ini file is opens only for record count purpose.you are not reading any data from the file.
2)The code is not fully complete.
As of now its fine.Clarify you requirement and finish the code 1st.
Thanks,
DP

can you help me please can you finish it for me..
thanks for advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.