Okay so I'm pretty sure I've completely destroyed this code. All I'm trying to do is send the user-inputted product info into a binary file to display when the user chooses the report option from the menu. I'm so confused though and I think I really screwed it up.

// ** Prototypes **
void heading(void);
int menu();
void add();
void report();
char getstring(char entry, char prompt[]);
int getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total(double quantity, double amount);
double profit(double profit_cost, double profit_price);
void init_costs(double t[], int x);
void show_costs(double t[], int x);
void show(int prodnum, int prodtype, char d[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);
char firstUpper(char *buf);

typedef struct Sports
{
    int prodnum;
    int prodtype;
    char prodscrip;
    int prodquan;
    double cost;
    double price;
} Sports;

/*  ================================================================  */

// ** Functions **

int main()
{

	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;

	do
	{


		select = menu();
		switch (select)
		{
		case 1: add(); break;
		case 2: report(); break;
		case 3:
		case 4:
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Sierra Sporting Goods\n\n");
	printf("1  =  Add a record\n");
	printf("2  =  Report\n");
	printf("3  =  Delete a record\n");
	printf("4  =  Change a record\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}

/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Sierra Sporting Goods\n\n\n");
	return;
}
/*  ================================================================  */

void add()
{

	double cost, price, prod_cost, prod_price, prod_profit;
	double MINCOST;
	double MAXCOST;
	double MINPRICE;
	double MAXPRICE;
	int prodnum, prodtype, prodquan;
	int MINPROD;
	int MAXPROD;
	int MINTYPE;
	int MAXTYPE;
	int MINQUAN;
	int MAXQUAN;
	char prodscrip;
	double types[6];
	char choice;
	char line[1][6];
	Sports s;
	FILE *fp;
	

	init_costs(types,6);
	fp = fopen("limits.txt", "rt");
	if (fp == NULL)
		{
		printf("File does not exist");
		return;
		}

	else 
		{
		fscanf_s(fp, "%d %d %d %d %d %d %lf %lf %lf %lf", &MINPROD, &MAXPROD, &MINTYPE, &MAXTYPE, &MINQUAN, &MAXQUAN, &MINCOST, &MAXCOST, &MINPRICE, &MAXPRICE);
	fclose(fp);
		}

	fp = fopen("data.dat", "ab");
	if (fp == NULL)
   {
   message("Error opening data file\a");
   return;
   }


	do
	{
		heading();
		s.prodnum = getint(MINPROD, MAXPROD, "product number");
		s.prodtype = getint(MINTYPE, MAXTYPE, "product type");
		
		s.prodscrip = getstring(prodscrip, "Enter the product description: ");
		s.prodscrip = firstUpper(&prodscrip);
		
		s.prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
		s.cost = getreal(MINCOST, MAXCOST, "product cost");
		s.price = getreal(MINPRICE, MAXPRICE, "product price");
		prod_cost = total(prodquan, cost);
		prod_price = total(prodquan, price);
		prod_profit = profit(prod_price, prod_cost);

		types[prodtype] += prod_cost;

		show(prodnum, prodtype, prodscrip, prodquan, cost, price, prod_price, prod_cost, prod_profit);
		choice = prompt("Would you like to enter another product");
	}
	while (choice != 'N');
	getchar();
		show_costs(types,6);


	return;
}
/*  ================================================================  */
char firstUpper(char *buf)
{
    while (*buf)  // Continue as long as characters available.
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // Skip all spaces until next character.
        *buf = toupper(*buf);   // Capitalize first character after space.
        while(*buf && !isspace(*buf) )
            *buf++;         // Skip all characters until next space.
    }
}

/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter the %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */

double getreal(double min, double max, char item[])
{						
	double y;

	printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
	scanf("%lf%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
		scanf("%lf%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double amount)
{
	return (quantity * amount);
}
/*  ================================================================  */

double profit(double profit_price, double profit_cost)
{
	return (profit_price - profit_cost);
}
/*  ================================================================  */

void init_costs(double *t, int x)
{
	int z;

	for (z = 1; z < x; z++)
		*(t + z) = 0;

}
/*  ================================================================  */

void show_costs(double *t, int x)
{
	int z;
	double total = 0;

	system("cls");

	printf(" Product Cost by Type\n\n");
	printf("_Type_____________Cost_\n\n");
	for (z = 1; z < x; z++)
	{
		printf(" %2d%20.2lf\n", z, *(t+z));
		total += *(t+z);
	}
	printf("________________________\n");
	printf("%23.2lf\n\n\n\n", total);
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */
void message(char *msg)
{
	printf("%s\n\n", *msg);
}
/*  ================================================================  */

int prompt(char *msg)
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nSierra Sporting Goods Database closed successfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}
/*  ================================================================  */
void show(int prodnum, int prodtype, char prodscrip, int prodquan, double cost, double price, 
		  double prod_price, double prod_cost, double prod_profit)
{

	printf("\n\n\nThe product number is ---------->  %04d\n", prodnum);
	printf("The product type is ------------>  %d\n", prodtype);
	printf("The product description is ----->  %s\n", prodscrip);
	printf("The quantity is ---------------->  %d\n", prodquan);
	printf("The cost is -------------------->  $%.2lf\n", cost);
	printf("The price is ------------------->  $%.2lf\n\n", price);

	printf("Total product price ----------> $%.2lf\n", prod_price);
	printf("Total product cost -----------> $%.2lf\n", prod_cost);
	printf("Total product profit ---------> $%.2lf\n\n\n\n", prod_profit);

	return;
}

/*  ================================================================  */

	void report()
	{
	int data;
	    FILE *fp;
	    struct Sports s;
	fp = fopen(“data.dat”, “ab”);
	while (fread(&s, sizeof(s), 1, fp) != 0)
		{
		show();
		}
	fclose(fp);
	}

> fp = fopen(“data.dat”, “ab”);
What sort of quotes are these?

> show();
show() expects a lot of parameters.

Next time, post error messages.

Also, when you've got something which does something useful, make a copy of it.

I thought

fp = fopen(“data.dat”, “ab”);

was the right way to code it. It's what my teacher wrote in our lecture.

What do you mean when I have something useful make a copy of it? I'm confused... I'm just trying to learn how to do this stuff and my teacher is of absolutely no help whatsoever, not to mention that according to you his syntax isn't even correct! I don't understand that though because at the top of my code I reference another file using the same format and I haven't gotten an error for it.

I thought
fp = fopen(“data.dat”, “ab”);

was the right way to code it.

no. it's fp = fopen("data.dat", "ab"); (wrong quotes)

What do you mean when I have something useful make a copy of it?

He means ALWAYS backup, backup your backups and back them up ;)

Now tell us, what compiler errors your have, or what errors your program output has.

And as Salem said:

> show();
show() expects a lot of parameters.

Good lord I'm so confused lol. What part of my version was wrong? I'm supposed to use different quotes? Where in the world are they? lol. It's finals week and I'm exhausted heh.

As far as the backups go, I do have a backup, I just wasnt sure if I wanted to go all the way back to it, and even that one was having problems running as well. But I am going to go back to it because I am way too far gone on this one and I need to figure out why the last one isn't working. It's having trouble opening the text file for some reason and I can't figure out why because I added it as a resource. The program runs but when it asks me to enter a selection I choose 1 to add a record and it flashes "file does not exist" really quickly and then does nothing. Hopefully when I fix this the rest will be easier. Here it is:

// ** Prototypes **
void heading(void);
int menu();
int add();
void getstring(char entry[], char prompt[]);
int getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total(double quantity, double amount);
double profit(double profit_cost, double profit_price);
void init_costs(double t[], int x);
void show_costs(double t[], int x);
void show(int prodnum, int prodtype, char d[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);
void firstUpper(char *buf);

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

/* ================================================================== */

// ** Functions **

int main()

	{
	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;

	do
	{

		select = menu();
		switch (select)
		{
		case 1: add(); break;
		case 2:
		case 3:
		case 4:
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Sierra Sporting Goods\n\n");
	printf("1  =  Add a record\n");
	printf("2  =  Report\n");
	printf("3  =  Delete a record\n");
	printf("4  =  Change a record\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Sierra Sporting Goods\n\n\n");
	return;
}
/*  ================================================================  */

int add()
{
	double cost, price, prod_cost, prod_price, prod_profit;
	double MINCOST;
	double MAXCOST;
	double MINPRICE;
	double MAXPRICE;
	int prodnum, prodtype, prodquan;
	int MINPROD;
	int MAXPROD;
	int MINTYPE;
	int MAXTYPE;
	int MINQUAN;
	int MAXQUAN;
	char prodscrip[40];
	double types[6];
	char choice;
	FILE *fp;
	char line[1][6];

	init_costs(types,6);
	
	fp = fopen("limits.txt", "rt");
	if (fp == NULL)
		{
		printf("File does not exist");
		return 0;
		}

	 else
		 {
		 fscanf(fp, "%d %d %d %d %d %d %lf %lf %lf %lf", &MINPROD, &MAXPROD, &MINTYPE, &MAXTYPE, &MINQUAN, &MAXQUAN, &MINCOST, &MAXCOST, &MINPRICE, &MAXPRICE);
		 }
	fclose(fp);
	do
	{
		heading();
		
		prodnum = getint(MINPROD, MAXPROD, "product number");
		prodtype = getint(MINTYPE, MAXTYPE, "product type");
		
		printf("Enter the product description: ");
		gets(prodscrip);
		firstUpper(prodscrip);
		
		prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
		cost = getreal(MINCOST, MAXCOST, "product cost");
		price = getreal(MINPRICE, MAXPRICE, "product price");
		prod_cost = total(prodquan, cost);
		prod_price = total(prodquan, price);
		prod_profit = profit(prod_price, prod_cost);

		types[prodtype] += prod_cost;

		show(prodnum, prodtype, prodscrip, prodquan, cost, price, prod_price, prod_cost, prod_profit);
		choice = prompt("Would you like to enter another product");
	}
	while (choice != 'N');
	getchar();
		show_costs(types,6);
		


	
	return 0;
}
/*  ================================================================  */
void firstUpper(char *buf)
{
    while (*buf)  // Continue as long as characters available.
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // Skip all spaces until next character.
        *buf = toupper(*buf);   // Capitalize first character after space.
        while(*buf && !isspace(*buf) )
            *buf++;         // Skip all characters until next space.
    }
}

/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter the %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */

double getreal(double min, double max, char item[])
{						
	double y;

	printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
	scanf("%lf%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
		scanf("%lf%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double amount)
{
	return (quantity * amount);
}
/*  ================================================================  */

double profit(double profit_price, double profit_cost)
{
	return (profit_price - profit_cost);
}
/*  ================================================================  */

void init_costs(double *t, int x)
{
	int z;

	for (z = 1; z < x; z++)
		*(t + z) = 0;

}
/*  ================================================================  */

void show_costs(double *t, int x)
{
	int z;
	double total = 0;

	system("cls");

	printf(" Product Cost by Type\n\n");
	printf("_Type_____________Cost_\n\n");
	for (z = 1; z < x; z++)
	{
		printf(" %2d%20.2lf\n", z, *(t+z));
		total += *(t+z);
	}
	printf("________________________\n");
	printf("%23.2lf\n\n\n\n", total);
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */
void message(char *msg)
{
	printf("%s\n\n", *msg);
}
/*  ================================================================  */

int prompt(char *msg)
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nSierra Sporting Goods Database closed successfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}
/*  ================================================================  */
void show(int prodnum, int prodtype, char prodscrip[], int prodquan, double cost, double price, 
		  double prod_price, double prod_cost, double prod_profit)
{

	printf("\n\n\nThe product number is ---------->  %04d\n", prodnum);
	printf("The product type is ------------>  %d\n", prodtype);
	printf("The product description is ----->  %s\n", prodscrip);
	printf("The quantity is ---------------->  %d\n", prodquan);
	printf("The cost is -------------------->  $%.2lf\n", cost);
	printf("The price is ------------------->  $%.2lf\n\n", price);

	printf("Total product price ----------> $%.2lf\n", prod_price);
	printf("Total product cost -----------> $%.2lf\n", prod_cost);
	printf("Total product profit ---------> $%.2lf\n\n\n\n", prod_profit);

	return;
}
/*  ================================================================  */

Alright the limits file wasn't working because it got moved out of the lab folder. so now this whole code works and I just need to use a structure and binary record to make the report() function.

Alright so it looks like I'm still getting an error... When I select 5 to quit and it asks if I'm sure, if I type "Y" it breaks and I get a window that says "Unhandled exception at 0x1029984f (msvcr90d.dll) in lab 10 FIX.exe: 0xC0000005: Access violation reading location 0x0000000a.

It then opens the output file and goes to line 1624 which says "while (i-- && *p)".

What am I doing wrong??

When I select 5 to quit and it asks if I'm sure, if I type "Y" it breaks and I get a window that says "Unhandled exception at 0x1029984f (msvcr90d.dll) in lab 10 FIX.exe: 0xC0000005: Access violation reading location 0x0000000a.

Change your message() function to following

void message(char *msg)
{
    printf("%s\n\n", msg); // <- asterisk preceding msg now removed
}

Oh wow awesome, thanks!

So now I am starting with fresh code (or rather the error-free code from my previous lab). Now I am editing this lab using struct and binary record to accept the user-inputted data and display it as a report when the user selects report from the menu.

The only problems I'm having now are storing the prodscrip in the binary file after it runs through the firstUpper() function, and getting the report to display.

BTW, there is a limits file included and it looks like this:

1 9999
1 5
1 50
5.00 900.00
6.00 1000.00

Here is the code:

// ** Prototypes **
void heading(void);
int menu();
int add();
void report();
void getstring(char entry[], char prompt[]);
int getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total(double quantity, double amount);
double profit(double profit_cost, double profit_price);
void init_costs(double t[], int x);
void show_costs(double t[], int x);
void show(int prodnum, int prodtype, char d[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);
void firstUpper(char *buf);

struct sports
{
    int prodnum;
    int prodtype;
    char prodscrip;
    int prodquan;
    double cost;
    double price;
};

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "10 final.h"

/* ================================================================== */

// ** Functions **

int main()

	{
	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;


	do
	{

		select = menu();
		switch (select)
		{
		case 1: add(); break;
		case 2: report(); break;
		case 3:
		case 4:
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Sierra Sporting Goods\n\n");
	printf("1  =  Add a record\n");
	printf("2  =  Report\n");
	printf("3  =  Delete a record\n");
	printf("4  =  Change a record\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Sierra Sporting Goods\n\n\n");
	return;
}
/*  ================================================================  */

int add()
{
	double cost, price, prod_cost, prod_price, prod_profit;
	double MINCOST;
	double MAXCOST;
	double MINPRICE;
	double MAXPRICE;
	int prodnum, prodtype, prodquan;
	int MINPROD;
	int MAXPROD;
	int MINTYPE;
	int MAXTYPE;
	int MINQUAN;
	int MAXQUAN;
	char prodscrip[40];
	double types[6];
	char choice;
	FILE *fp;
	FILE *f;
	char line[1][6];
	init_costs(types,6);
	struct sports s;
	

	fp = fopen("limits.txt", "rt");
	
	if (fp == NULL)
		{
		printf("File does not exist");
		return 0;
		}

	 else
		 {
		 fscanf(fp, "%d %d %d %d %d %d %lf %lf %lf %lf", &MINPROD, &MAXPROD, &MINTYPE, &MAXTYPE, &MINQUAN, &MAXQUAN, &MINCOST, &MAXCOST, &MINPRICE, &MAXPRICE);
		 }
	fclose(fp);


	f = fopen("data.dat", "ab");
	if (f == NULL)
   {
   message("Error opening data file\a");
   return 1;
   }
	
	do
	{
		heading();
		
		s.prodnum = getint(MINPROD, MAXPROD, "product number");
		s.prodtype = getint(MINTYPE, MAXTYPE, "product type");
		
		printf("Enter the product description: ");
		gets(prodscrip);
		firstUpper(prodscrip);
		
		s.prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
		s.cost = getreal(MINCOST, MAXCOST, "product cost");
		s.price = getreal(MINPRICE, MAXPRICE, "product price");
		prod_cost = total(s.prodquan, s.cost);
		prod_price = total(s.prodquan, s.price);
		prod_profit = profit(prod_price, prod_cost);

		types[s.prodtype] += prod_cost;

		show(s.prodnum, s.prodtype, prodscrip, s.prodquan, s.cost, s.price, prod_price, prod_cost, prod_profit);
		
		choice = prompt("Would you like to enter another product");
	}
	while (choice != 'N');
	getchar();
		show_costs(types,6);
		


	
	return 0;
	fclose(f);
}

/*  ================================================================  */
void firstUpper(char *buf)
{
    while (*buf)  // Continue as long as characters available.
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // Skip all spaces until next character.
        *buf = toupper(*buf);   // Capitalize first character after space.
        while(*buf && !isspace(*buf) )
            *buf++;         // Skip all characters until next space.
    }
}

/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter the %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */

double getreal(double min, double max, char item[])
{						
	double y;

	printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
	scanf("%lf%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
		scanf("%lf%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double amount)
{
	return (quantity * amount);
}
/*  ================================================================  */

double profit(double profit_price, double profit_cost)
{
	return (profit_price - profit_cost);
}
/*  ================================================================  */

void init_costs(double *t, int x)
{
	int z;

	for (z = 1; z < x; z++)
		*(t + z) = 0;

}
/*  ================================================================  */

void show_costs(double *t, int x)
{
	int z;
	double total = 0;

	system("cls");

	printf(" Product Cost by Type\n\n");
	printf("_Type_____________Cost_\n\n");
	for (z = 1; z < x; z++)
	{
		printf(" %2d%20.2lf\n", z, *(t+z));
		total += *(t+z);
	}
	printf("________________________\n");
	printf("%23.2lf\n\n\n\n", total);
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */
void message(char *msg)
{
	printf("%s\n\n", msg);
}
/*  ================================================================  */

int prompt(char *msg)
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nSierra Sporting Goods Database closed successfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}
/*  ================================================================  */

void show(int prodnum, int prodtype, char prodscrip[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit)
{

	printf("\n\n\nThe product number is ---------->  %04d\n", prodnum);
	printf("The product type is ------------>  %d\n", prodtype);
	printf("The product description is ----->  %s\n", prodscrip);
	printf("The quantity is ---------------->  %d\n", prodquan);
	printf("The cost is -------------------->  $%.2lf\n", cost);
	printf("The price is ------------------->  $%.2lf\n\n", price);

	printf("Total product price ----------> $%.2lf\n", prod_price);
	printf("Total product cost -----------> $%.2lf\n", prod_cost);
	printf("Total product profit ---------> $%.2lf\n\n\n\n", prod_profit);

	return;
}
/*  ================================================================  */

void report()

{
	double prod_profit, prod_cost, prod_price; 
	char prodscrip[40];
	FILE *fp;
	struct sports s;
	
	fp = fopen("data.dat","ab");
	while (fread(&s, sizeof(s), 10, fp) != 0)
		{
		show(s.prodnum, s.prodtype, prodscrip, s.prodquan, s.cost, s.price, prod_cost, prod_price, prod_profit);
		}
	fclose(fp);
	printf("Press ENTER to return to the Main Menu...");
	getchar();

	}
/*  ================================================================  */

Alright, worked on it for a while and sort of did the report() function but I don't think it's quite the right way, and none of the values are showing up right.

// ** Prototypes **
void heading(void);
int menu();
int add();
void report();
void getstring(char entry[], char prompt[]);
int getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total(double quantity, double amount);
double profit(double profit_cost, double profit_price);
void init_costs(double t[], int x);
void show_costs(double t[], int x);
void show(int prodnum, int prodtype, char d[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);
void firstUpper(char *buf);

struct sports
{
    int prodnum;
    int prodtype;
    char prodscrip;
	int prodquan;
    double cost;
    double price;
};

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "10 final.h"

/* ================================================================== */

// ** Functions **

int main()

	{
	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;


	do
	{

		select = menu();
		switch (select)
		{
		case 1: add(); break;
		case 2: report(); break;
		case 3:
		case 4:
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Sierra Sporting Goods\n\n");
	printf("1  =  Add a record\n");
	printf("2  =  Report\n");
	printf("3  =  Delete a record\n");
	printf("4  =  Change a record\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Sierra Sporting Goods\n\n\n");
	return;
}
/*  ================================================================  */

int add()
{
	double cost, price, prod_cost, prod_price, prod_profit;
	double MINCOST;
	double MAXCOST;
	double MINPRICE;
	double MAXPRICE;
	int prodnum, prodtype, prodquan;
	int MINPROD;
	int MAXPROD;
	int MINTYPE;
	int MAXTYPE;
	int MINQUAN;
	int MAXQUAN;
	char prodscrip[20];
	double types[6];
	char choice;
	FILE *fp;
	FILE *f;
	char line[1][6];
	init_costs(types,6);
	struct sports s;
	

	fp = fopen("limits.txt", "rt");
	
	if (fp == NULL)
		{
		printf("File does not exist");
		return 0;
		}

	 else
		 {
		 fscanf(fp, "%d %d %d %d %d %d %lf %lf %lf %lf", &MINPROD, &MAXPROD, &MINTYPE, &MAXTYPE, &MINQUAN, &MAXQUAN, &MINCOST, &MAXCOST, &MINPRICE, &MAXPRICE);
		 }
	fclose(fp);


	f = fopen("data.dat", "ab");
	if (f == NULL)
   {
   message("Error opening data file\a");
   return 1;
   }
	
	do
	{
		heading();
		
		s.prodnum = getint(MINPROD, MAXPROD, "product number");
		s.prodtype = getint(MINTYPE, MAXTYPE, "product type");
		
		printf("Enter the product description: ");
		gets(prodscrip);
		firstUpper(prodscrip);
		
		s.prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
		s.cost = getreal(MINCOST, MAXCOST, "product cost");
		s.price = getreal(MINPRICE, MAXPRICE, "product price");
		prod_cost = total(s.prodquan, s.cost);
		prod_price = total(s.prodquan, s.price);
		prod_profit = profit(prod_price, prod_cost);

		types[s.prodtype] += prod_cost;

		fwrite(&s,sizeof(struct sports),6,fp);

		show(s.prodnum, s.prodtype, prodscrip, s.prodquan, s.cost, s.price, prod_price, prod_cost, prod_profit);
		
		choice = prompt("Would you like to enter another product");
	}
	while (choice != 'N');
	getchar();
		show_costs(types,6);
		


	
	return 0;
	fclose(f);
}

/*  ================================================================  */
void firstUpper(char *buf)
{
    while (*buf)  // Continue as long as characters available.
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // Skip all spaces until next character.
        *buf = toupper(*buf);   // Capitalize first character after space.
        while(*buf && !isspace(*buf) )
            *buf++;         // Skip all characters until next space.
    }
}

/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter the %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */

double getreal(double min, double max, char item[])
{						
	double y;

	printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
	scanf("%lf%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
		scanf("%lf%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double amount)
{
	return (quantity * amount);
}
/*  ================================================================  */

double profit(double profit_price, double profit_cost)
{
	return (profit_price - profit_cost);
}
/*  ================================================================  */

void init_costs(double *t, int x)
{
	int z;

	for (z = 1; z < x; z++)
		*(t + z) = 0;

}
/*  ================================================================  */

void show_costs(double *t, int x)
{
	int z;
	double total = 0;

	system("cls");

	printf(" Product Cost by Type\n\n");
	printf("_Type_____________Cost_\n\n");
	for (z = 1; z < x; z++)
	{
		printf(" %2d%20.2lf\n", z, *(t+z));
		total += *(t+z);
	}
	printf("________________________\n");
	printf("%23.2lf\n\n\n\n", total);
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */
void message(char *msg)
{
	printf("%s\n\n", msg);
}
/*  ================================================================  */

int prompt(char *msg)
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nSierra Sporting Goods Database closed successfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}
/*  ================================================================  */

void show(int prodnum, int prodtype, char prodscrip[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit)
{

	printf("\n\n\nThe product number is ---------->  %04d\n", prodnum);
	printf("The product type is ------------>  %d\n", prodtype);
	printf("The product description is ----->  %s\n", prodscrip);
	printf("The quantity is ---------------->  %d\n", prodquan);
	printf("The cost is -------------------->  $%.2lf\n", cost);
	printf("The price is ------------------->  $%.2lf\n\n", price);

	printf("Total product price ----------> $%.2lf\n", prod_price);
	printf("Total product cost -----------> $%.2lf\n", prod_cost);
	printf("Total product profit ---------> $%.2lf\n\n\n\n", prod_profit);

	return;
}
/*  ================================================================  */

void report()

{
	double prod_profit = 0, total_profit = 0;
	char prodscrip[20];
	FILE *fp;
	struct sports s;
	
	
	system("cls");

	fp = fopen("data.dat","ab");
	if (fp == NULL)
		{
		printf("File does not exist");
		return;
		}
	else
		{
	fread(&s, sizeof(s), 10, fp);
	printf(" Sierra Sporting Goods\n\n");
	printf("__Prod #___Type___Description____________Qty___Cost____Price____Profit__\n\n");
	
	prod_profit = (s.price - s.cost) * s.prodquan;
	total_profit += prod_profit;

	printf(" %3d%5d%5s%4d%3.2f%3.2f%3.2f\n", s.prodnum, s.prodtype, prodscrip, s.prodquan, s.cost, s.price, prod_profit);
	printf("________________________________________________________________________\n");
	printf("  Total Expected Profit%46.2f\n\n\n\n", total_profit);
	printf("Press ENTER to return to the Main Menu...");
	getchar();
		}
	fclose(fp);

	}
/*  ================================================================  */

Come on everyone, help a girl out... I really need to figure out what I'm doing wrong or I'm gonna blow it when I do my final program :(

P.S. I didn't mean to imply that you should help me because I'm a girl, it's just something I say sort of like help a brother out. Just wanted to clear that up!

I think you could start to tackle the problem by using fprintf() to write data to the file. Since you already know how to use printf(), it should be easy, see
http://www.cplusplus.com/reference/clibrary/cstdio/fprintf.html

After you've managed to get a record written to a file, the next step is to handle record deletions/insertions/changes.

Okay so I made a bunch of changes and now I'm getting the data into the file and displaying the report but it is completely messed up. The description won't display properly, the values get all messed up, I can't return to the menu once the report is finished. It just keeps printing a report with different messed up values. I have no idea what to do from here and this is taking WAY too long especially given the fact that this is one of four finals I have to do by Friday. Here's what I have now:

// ** Prototypes **
void heading(void);
int menu();
int add();
void report();
void getstring(char *entry, char * prompt);
int getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total(double quantity, double amount);
double profit(double profit_cost, double profit_price);
void init_costs(double t[], int x);
void show_costs(double t[], int x);
void show(int prodnum, int prodtype, char d[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);
void firstUpper(char *buf);
void line(char c, int t);

struct sports
{
    int prodnum;
    int prodtype;
    char prodscrip[20];
	int prodquan;
    double cost;
    double price;
};

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "10 final.h"

/* ================================================================== */

// ** Functions **

#define clrscr() system("cls")

int main()

	{
	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;


	do
	{

		select = menu();
		switch (select)
		{
		case 1: add(); break;
		case 2: report(); break;
		case 3:
		case 4:
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Sierra Sporting Goods\n\n");
	printf("1  =  Add a record\n");
	printf("2  =  Report\n");
	printf("3  =  Delete a record\n");
	printf("4  =  Change a record\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Sierra Sporting Goods\n\n\n");
	return;
}
/*  ================================================================  */

int add()
{
	double cost, price, prod_cost, prod_price, prod_profit;
	double MINCOST;
	double MAXCOST;
	double MINPRICE;
	double MAXPRICE;
	int prodnum, prodtype, prodquan;
	int MINPROD;
	int MAXPROD;
	int MINTYPE;
	int MAXTYPE;
	int MINQUAN;
	int MAXQUAN;
	int i;
	char prodscrip[20];
	double types[6];
	char choice;
	FILE *fp;
	FILE *f;
	char line[1][6];
	init_costs(types,6);
	struct sports s;
	

	f = fopen("limits.txt", "rt");
	
	if (f == NULL)
		{
		printf("File does not exist");
		return 0;
		}

	 else
		 {
		 fscanf(f, "%d %d %d %d %d %d %lf %lf %lf %lf", &MINPROD, &MAXPROD, &MINTYPE, &MAXTYPE, &MINQUAN, &MAXQUAN, &MINCOST, &MAXCOST, &MINPRICE, &MAXPRICE);
		 }
	fclose(f);


	fp = fopen("data.dat", "ab");
	if (fp == NULL)
   {
   message("Error opening data file\a");
   return 1;
   }
	
	do
	{
		heading();
		
		s.prodnum = getint(MINPROD, MAXPROD, "product number");
		s.prodtype = getint(MINTYPE, MAXTYPE, "product type");
		
		getstring(s.prodscrip, "product description: ");
		s.prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
		s.cost = getreal(MINCOST, MAXCOST, "product cost");
		s.price = getreal(MINPRICE, MAXPRICE, "product price");
		prod_cost = total(s.prodquan, s.cost);
		prod_price = total(s.prodquan, s.price);
		prod_profit = profit(prod_price, prod_cost);

		types[s.prodtype] += prod_cost;

		fwrite(&s,sizeof(struct sports),6,fp);

		show(s.prodnum, s.prodtype, s.prodscrip, s.prodquan, s.cost, s.price, prod_price, prod_cost, prod_profit);
		
		choice = prompt("Would you like to enter another product");
	}
	while (choice != 'N');
	getchar();
		show_costs(types,6);
		


	
	return 0;
	fclose(fp);
}

/*  ================================================================  */
void firstUpper(char *buf)
{
    while (*buf)  // Continue as long as characters available.
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // Skip all spaces until next character.
        *buf = toupper(*buf);   // Capitalize first character after space.
        while(*buf && !isspace(*buf) )
            *buf++;         // Skip all characters until next space.
    }
}

/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter the %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */
void getstring(char *entry, char * prompt)
{
printf("Enter the %s: ", prompt);
gets(entry);
}

/*  ================================================================  */
double getreal(double min, double max, char item[])
{						
	double y;

	printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
	scanf("%lf%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("Enter the %s between $%.2lf and $%.2lf: ", item, min, max);
		scanf("%lf%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double amount)
{
	return (quantity * amount);
}
/*  ================================================================  */

double profit(double profit_price, double profit_cost)
{
	return (profit_price - profit_cost);
}
/*  ================================================================  */

void init_costs(double *t, int x)
{
	int z;

	for (z = 1; z < x; z++)
		*(t + z) = 0;

}
/*  ================================================================  */

void show_costs(double *t, int x)
{
	int z;
	double total = 0;

	system("cls");

	printf(" Product Cost by Type\n\n");
	printf("_Type_____________Cost_\n\n");
	for (z = 1; z < x; z++)
	{
		printf(" %2d%20.2lf\n", z, *(t+z));
		total += *(t+z);
	}
	printf("________________________\n");
	printf("%23.2lf\n\n\n\n", total);
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */
void message(char *msg)
{
	printf("%s\n\n", msg);
}
/*  ================================================================  */
void line(char c, int t)
{
while (t--) putchar(c);
putchar('\n');
}
/*  ================================================================  */
int prompt(char *msg)
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */
int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nSierra Sporting Goods Database closed successfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */
int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}
/*  ================================================================  */
void show(int prodnum, int prodtype, char prodscrip[], int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit)
{
struct sports s;

	printf("\n\n\nThe product number is ---------->  %04d\n", prodnum);
	printf("The product type is ------------>  %d\n", prodtype);
	printf("The product description is ----->  %s\n", s.prodscrip);
	printf("The quantity is ---------------->  %d\n", prodquan);
	printf("The cost is -------------------->  $%.2lf\n", cost);
	printf("The price is ------------------->  $%.2lf\n\n", price);

	printf("Total product price ----------> $%.2lf\n", prod_price);
	printf("Total product cost -----------> $%.2lf\n", prod_cost);
	printf("Total product profit ---------> $%.2lf\n\n\n\n", prod_profit);

	return;
}
/*  ================================================================  */
void report()

{
	double prod_profit = 0, total_profit = 0;
	char prodscrip[20];
	FILE *fp;
	struct sports s;
	int c;
	
	clrscr();

printf("Sierra Sporting Goods\n");
	fp = fopen("data.dat","rb");
	if (fp == NULL)
		{
		printf("File does not exist");
		return;
		}
	printf("Product Inventory\n\n");
	c = printf("%-4s%5s%20s%8s%10s%10s%11s\n", "#", "Type", "Description", "Quantity", "Cost", "Price", "Profit");
	line('=', c-1);
	while (fread(&s, sizeof(s), 1, fp))
		{

	prod_profit = (s.price - s.cost) * s.prodquan;
	

	printf("%-4d%5d%22s%8d%10.2lf%10.2lf%11.2lf\n", s.prodnum, s.prodtype, s.prodscrip, s.prodquan, s.cost, s.price, prod_profit);
	line('=', c-1);
total_profit += prod_profit;
	printf(" Total Expected Profit%58.2f\n\n", total_profit);
	printf("Press ENTER to return to the Main Menu...");
	getchar();
		}
	fclose(fp);

	}
/*  ================================================================  */
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.