Help with a bit of tweeking on form feed
Hey Forum
can any one help me out by taking a look at this code, any suggestions are welcome(or critical)
The problem to solve is, a greengrocer has his daily produce enterd onto a magnetic disk at the end of each day.
The DAT file is already sorted serialy by type code and each rec ends with the (\n)
This prog is supposed to run a report off via the LPT1 port
and accumulate the totals of each product, and then the grand totals including profits(or non-profits)
The problem i have is how to set up the form feed i.e line counts,
and form feed(syntax)
Excuse the code as I'm still working on it, I've tried to describe what everthing does.
all help welcome
/*fill in a load of comments about the program*/
#include<stdio.h>
#include<time.h>
#define SIZE sizeof(struct stock_rec)
#define LINES_PER_PAGE 60 //length of page I presume
struct stock_rec { // the structure
char ref_num[5];
int type_code[5];
int weight;
int quantity;
int calc_method[1];
float buy_price;
float sale_price;
};
void print_report(struct stock_rec *out_str); //the user defined functions
int error(int i);
float calc_meth1(float b_val); //these are not yet complete
float calc_meth2(float s_val); //and are not a problem
float gross_profit(float p_val);
void clrscr(void); //probably won’t use this
time_t time_in_secs; //global variables
float value;
FILE *in_data_fp, *out_prn_ptr;
//Right I’ve used these arrays to help with the formatting of the ouput
//as we are taught not to use (\t) due to individual machines set up
char title[][10] ={ "Buying","Sale","Profit","Reference","Type",
"weight","Qty","Calc","Price","Value","No","Kilos" ,
"Meth","\0"
};
char foot[][30] = {"Totals potatoes","Totals turnips","Totals peas",
"Totals carrots","Totals sprouts","Totals tinned_Veg",
"Calc meth 1= weight * price","2= qty * price","\0"
};
char symbol[][1] = {'P','$'};
void main()
{
struct stock_rec *prod_ptr; //pointer to struct
static int tot_b_price=0, tot_s_price=0; //use of static for permanent address
static int count, lines;
static int **code_ptr1, **code_ptr2;
if( ( out_prn_ptr = fopen("LPT1", "w")) == NULL)
error(1);
if( ( in_data_fp = fopen("A:PRODUCE.DAT", "r")) == NULL)
error(2);
while(!EOF)
{
if( (fread(&prod_ptr, SIZE, 1, in_data_fp)) !=1)
error(3);
*code_ptr1=prod_ptr->type_code; //I’ve a pointer to pointer so I
lines=0; //test type code for change
//any idea’s welcome
while(!'\n')
{
*code_ptr2 = *code_ptr1+1; //assign the type code pointers
//if the method is 1 or 2 then pass to a function
if(&prod_ptr->calc_method[0] != 0)
calc_meth1(value);
else
calc_meth2(value);
//accumulate the totals then use in another function later
tot_b_price+=prod_ptr->buy_price;
tot_s_price+=prod_ptr->sale_price;
lines++; //not sure if I should use this here
code_ptr1++;
}
gross_profit(value);
print_report(prod_ptr); //output the record to the printer
code_ptr2++;
if(code_ptr1!=code_ptr2) //test the type code here
gross_profit(value);
}
printf("\nEnd of daily stock report");
fclose(out_prn_ptr);
fclose(in_data_fp);
}
int error(int i) //error func
{
char *e[ ] = {"\nUnable to access printer\nProgram halted",
"\nUnable to open file at A: drive\nProgram abandoned",
"\nUnable to read data\n File corrupt"};
printf("\a%s", e[i]); //sound bell and display msg
}
void print_report(struct stock_rec *out_str)
{
int count, lines;
struct tm todays_date;
time_in_secs = time(NULL);
todays_date = *localtime(&time_in_secs);
printf("\tMr Greens (Wholesaler) - Daily Sales Report");
printf("%13d/%d/%d", todays_date.tm_mday,todays_date.tm_mon+1,todays_da te.tm_year);
printf("\t\tPage %4d", count);
printf("\n%40s %20s %20s", title[0],title[1],title[2]);
printf("\n%9s %6s %9s %6s %6s %9s %11s %13s %11s",title[3],title[4],
title[5], title[6], title[7], title[8], title[9], title[10],
title[11]);
printf("\n%7s %16s %12s %8c %9c %12c %9c", title[11], title[12],title[13],
symbol[1], symbol[2], symbol[1], symbol[2]);
//the above may look a bit messy, but I’ve run through my compiler and
//everything works ok, but the problem stats here, the variable may need //attention but as I said any idea’s are welcome
//with the line count and the form feed
for(count=0; count!=EOF; count++)
{
printf("\n\n%8.6s %5.1d %10.4d %7.4d %5.1d %10.5f %10.5f"
"%17.5f %10.7f", out_str->ref_num, out_str->type_code,
out_str->weight, out_str->quantity, out_str->calc_method,
out_str->buy_price, out_str->sale_price);
if(lines>=LINES_PER_PAGE)
printf("\f");
}
}
//please ignore the rest
float calc_meth1(float b_val)
{
}
float calc_meth2(float s_val)
{
}
float gross_profit(float p_val)
{
}
again sorry for the length of the code, but you might say that i need a little more help than i thought
Thank in adce
:)