Hey,
I'm trying to link my .c file together with the .h file and I got a C1014 error that stated that I got "too many include files : depth = 1024" I need some help with this error. Did I do something wrong here?

Thanks.

This is the change2.c:

// Change.c
// Default constructor
#include "change1.h"
Change::Change()
{ SetAmount( 0.00 );
}

Change::Change( double dollars )
{  SetAmount( dollars );
}

void SetAmount( double dollars )
{ numTwenties = 0;
  numTens = 0;
  numFives = 0;
  numOnes = 0;
  numQuarters = 0;
  numDimes = 0;
  numNickels = 0;
  numPennies = 0;

  while( dollars >= 20.00 )
  { numTwenties++;
    dollars -= 20.00;
  }
  while( dollars >= 10.00 )
  { numTens++;
    dollars -= 10.00;
  }
  while( dollars >= 5.00 )
  { numFives++;
    dollars -= 5.00;
  }
  while( dollars >= 1.00 )
  { numOnes++;
    dollars -= 1.00;
  }
  while( dollars >= 0.25 )
  { numQuarters++;
    dollars -= 0.25;
  }
  while( dollars >= 0.10 )
  { numDimes++;
    dollars -= 0.10;
  }
  while( dollars >= 0.05 )
  { numNickels++;
    dollars -= 0.05;
  }
  while( dollars >= 0.01 )
  { numPennies++;
    dollars -= 0.01;
  }
}

double AmountInDollars()
{ return 20.0*numTwenties + 10.0*numTens + 5.0*numFives + numOnes + 0.25*numQuarters + 0.1*numDimes + 0.05*numNickels + 0.01*numPennies;
}

This is the change1.h:

// Change.h
#include "change2.c"
class Change
{ private:
    int numTwenties;
    int numTens;
    int numFives;
    int numOnes;
    int numQuarters;
    int numDimes;
    int numNickels;
    int numPennies; 
    
  public:
    Change();
    Change( double dollars );
    Change( int twenties, int tens, int fives, int ones, int quarters, int dimes, int nickels, int pennies );
    
    double AmountInDollars();
    void SetAmount( double dollars );

   // I would probably add a method for setting/getting each of the twenties/tens/etc.
    void SetTwenties( int twenties );
    int GetTwenties();
};

Your .c file is totally fine. The problem is your header file. You shouldn't include the .c file from the header. This causes a circular pattern that will recurse infinitely (.c includes .h includes .c includes .h includes .c ... ad infinitum). Your compiler simply stops this at some limit (1024) such that it doesn't crash your computer (basically it would cause the compiler to run an infinite loop). The proper way to write your header is as follows:

// Change.h

//below is a "header guard" (prevents a header from being included more than once)
#ifndef CHANGE_H
#define CHANGE_H

//include statements would come here. (but not change.c)

class Change
{ private:
    int numTwenties;
    int numTens;
    int numFives;
    int numOnes;
    int numQuarters;
    int numDimes;
    int numNickels;
    int numPennies; 
    
  public:
    Change();
    Change( double dollars );
    Change( int twenties, int tens, int fives, int ones, int quarters, int dimes, int nickels, int pennies );
    
    double AmountInDollars();
    void SetAmount( double dollars );

   // I would probably add a method for setting/getting each of the twenties/tens/etc.
    void SetTwenties( int twenties );
    int GetTwenties();
};

#endif //closes the header guard.
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.