Project Setup
Part of the Object Oriented Programming section of Coddy's C journey — lesson 22 of 61.
Challenge
EasyLet's begin building your Bank Account library! In this first step, you'll create the public interface—the header file that defines what operations exist without revealing any implementation details.
You'll create two files to set up the project foundation:
account.h: Your public header file. This is what users of your library will include. Declare an opaqueAccounttype using an incomplete type declaration—no struct body, just a forward declaration that tells the compiler the type exists. Then declare the function prototypes forcreate_account(takes an integer for the account ID and returns an Account pointer) anddestroy_account(takes an Account pointer and returns nothing). Don't forget include guards using the symbolACCOUNT_H.main.c: A simple test file to verify your header compiles correctly. Include your header and print a message confirming the interface is ready. Since we haven't implemented the functions yet, just print a confirmation message—the actual implementation comes in the next lesson.
The key insight here is that your header reveals what the Account module can do (create and destroy accounts) without showing how it stores data internally. Anyone including account.h will know an Account type exists and what functions are available, but they won't be able to access any internal fields—because you haven't defined any in the header!
Your main file should output:
Account interface readyThis sets the stage for the complete Bank Account system you'll build over the next several lessons. The header you create now will grow to include deposit, withdraw, and get_balance as you progress through the project.
Try it yourself
#include <stdio.h>
#include "account.h"
int main() {
// TODO: Print a message confirming the interface is ready
// The message should be: "Account interface ready"
return 0;
}
All lessons in Object Oriented Programming
1Modular Programming Basics
Header FilesInclude GuardsSource FilesStatic FunctionsRecap: Modular Calculator4Encapsulation
Opaque Pointers ConceptDefining Opaque StructsGetters and SettersValidation in SettersRecap: Secret Box2Objects and Methods
Structs as ObjectsThe 'Self' PointerConst CorrectnessPointer vs ValueHelper MethodsRecap: Point Manager5Project: Simple Bank Account
Project SetupImplementation of Account3Object Lifecycle
Constructor PatternDestructor PatternStack InitializationDeep CopyRecap: String Wrapper6Inheritance via Composition
Struct EmbeddingThe First Member RuleAccessing Parent MembersUpcastingRecap: Shape Hierarchy