ok. My files are properly opening now.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
/*
The cat struct is used for holding details of categories.
*/
struct cat
{
int id;
char description[25];
float vatrate;
};
/*
The item struct is used to describe a product
*/
struct item
{
char productname[25];
float price;
int catid;
};
void welcome();
typedef struct item product;
typedef struct cat category;
#define VRATES "productVat.txt"
#define VRATESpermission "r"
#define PRODUCT "products.txt"
#define PRODUCTpermission "r"
int main ()
{
//int k;
//char buf[BUFSIZ] = "Garbage";
FILE *prods;
FILE *rates;
if ((prods = fopen(PRODUCT, "r")) == NULL)
{
perror (PRODUCT);
return (EXIT_FAILURE);
}
if ((rates = fopen(VRATES, "r")) == NULL)
{
perror (VRATES);
return (EXIT_FAILURE);
}
/* k = 0;
while (fgets(buf, sizeof(buf), rates) != NULL)
{
printf (buf);
k++;
}*/
welcome();
fclose(prods);
fclose(rates);
}
void welcome()
{
printf ("\t\t\t\tWelcome\n");
}
How can i now load this data into my structs? I want the spaces to distinguish the different fields in the struct. I was thinking of using something like the following:
Code:
//Product array - holds all products in the shop
product productsarray[100];
//category array - used to hold the categories
category categoryarray[100];
//basket array holds the items they buy
product basket[100];
but i cant figure out how to do it like this properly. Any help appreciated!