• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

This is for AlexVirochovsky!

I am working with the code that you provided me from my last question.  I wanted ask you if you know why the program only compiles one time. I opened the program and compiled it. Then I closed it and reopened it again and it would not compile. The error I got was  declartion not allowed here in funciton main.  The error points to this line:
FILE *fIn  = fopen(szNameI,"rt");

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define discount 0.15
#define full_price 0.25
#define fed_tax 1.08
#define TRUE 1
#define FALSE 0

int Minutes(int s_hour, int s_minute, int e_hour, int e_minute,int *start);
void Customer_Summary(int call_count, long customer_time,double customer_charge);
double Bill(double c_time, int s_time);
void Total_Summary(int, int, double, double, double);
//1-st par: name of input,2-nd name of out
void main(int num, char *var[])
   char szNameI[255],szNameO[255];

   int total_calls = 0,
       total_customers = 0;

       long total_minutes = 0;
       double total_amount =0,total_charge = 0;
    double total_tax =0;

   if (num <= 1)

   if (num <= 2)
FILE *fIn  = fopen(szNameI,"rt");
      if (fIn)
FILE *fOut = fopen(szNameO,"wt");
while (!feof(fIn))
     char buff[81],szName[81],ac[10],phon[10];
     int number,i,hs,ms,he,me,start;
     double customer_charge = 0;
     long customer_duration = 0;

     if (!fgets(buff, sizeof(buff)-1, fIn))//1-st field: name
     strtok(buff, "\n"); //delete /n
     strcpy(szName,buff); //form name
     if (!fgets(buff, sizeof(buff)-1, fIn))//
break;//2-nd field: number
     number = atoi(buff);
        printf("\nCall                Start time    Ending time   Duration    Charge");
        for (i = 0; i < number; i++)
int start,duration;
double charge;

fgets(buff, sizeof(buff)-1, fIn);//next field: number + time
strtok(buff, "\n"); //delete /n
sscanf(buff,"%s %s %d:%d %d:%d",ac,phon,&hs,&ms,&he,&me);
duration = Minutes(hs,ms,he,me,&start);
charge = Bill(duration, start);
printf("\n %s %s         %02d:%02d          %02d:%02d %9d %11.2f",ac,phon,hs,ms,he,me
,duration, charge);
customer_charge += charge;
customer_duration += (long)duration;
     total_calls += number;
     total_minutes += customer_duration;
     total_tax += customer_charge * .08;
     total_charge += customer_charge;

     Customer_Summary(number, customer_duration, customer_charge);
      total_amount = total_charge*1.08; //???
      Total_Summary(total_customers, total_calls, total_minutes, total_amount, total_tax);

int Minutes(int s_hour, int s_minute, int e_hour, int e_minute,int *start)
      int iStart = s_hour *24 + s_minute;
      int iEnd   = e_hour *24 + e_minute;

   if (iStart > iEnd)
     iEnd += 24*60;
   *start = iStart;
   return iEnd - iStart;
// s_time: start time
// c_time: duration
//return money
double Bill(double c_time, int s_time)
  double charge;

  if ( (s_time > 8) || (s_time < 18) )
      charge = full_price * c_time;
      if (c_time > 60)
charge -= charge * 0.1;
      charge = discount * c_time;
      if (c_time > 60)
charge -= charge * 0.1;
  return charge;

void Customer_Summary(int call_count, long customer_time,double customer_charge)
  printf("\n\nThe total number of calls is:          %d", call_count);
  printf("\nThe total time used in minutes is:      %ld", customer_time);
  printf("\nThe total charge is:                    $%.2f", customer_charge);
  printf("\nThe total tax is:                      $%.2f", customer_charge * .08);
  printf("\nThe total amount due is:               $%.2f", customer_charge + (customer_charge * .08));

void Total_Summary(int total_customers, int total_calls, double total_minutes,
   double total_amount, double total_tax)
  printf("\nTOTAL SUMMARY\n");
  printf("\nThe total number of customers:     %d", total_customers);
  printf("\nthe total number of calls is:      %d", total_calls);
  printf("\nThe total amount of time is:       %.0f", total_minutes);
  printf("\nThe total amount is:               $%.2f", total_amount);
  printf("\nthe total tax is:                  $%.2f", total_tax);
1 Solution
What translator do you use?
May be it is simple "C".
In this case
1. After
>>void main(int num, char *var[])
   FILE *fIn;
2. instead of
>>   FILE *fIn  = fopen(szNameI,"rt");
   fIn  = fopen(szNameI,"rt");
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now