An example project implementing object-oriented programming paradigms using pure C.
You can view the translation in your preferred language by clicking on the corresponding link below.
π English | νκ΅μ΄ | δΈζ | ζ₯ζ¬θͺ | Π ΡΡΡΠΊΠΈΠΉ | FranΓ§ais | EspaΓ±ol | Italiano | PortuguΓͺs | ΰ€Ήΰ€Ώΰ€¨ΰ₯ΰ€¦ΰ₯ | Ψ§ΩΨΉΨ±Ψ¨ΩΨ©
This project is an example that implements key concepts of object-oriented programming (abstraction, encapsulation, inheritance, polymorphism) in a modular structure using only the C language (C99 standard). Various system components (System
), threading (Thread
), console I/O (Console
), input scanning (Scanner
), and algorithms (Algorithm
) are expressed as objects using structs and function pointers.
- System: Basic I/O, file I/O, timer, platform abstraction
- Thread: Lightweight thread creation and management
- Console: Console I/O formatting and control
- Scanner: Input stream utilities
- Algorithm: Stack, Queue, Deque, List collections
This project has been tested and runs on the following platforms:
- πͺ Windows 10 / 11
- π§ Linux
- π macOS
- Object-Oriented Programming in C
- Thread and Mutex abstraction
- Console I/O utilities
- Input Scanner for primitive types
- Data Structures: Stack, Queue, List
- Advanced File utilities
- GUI Layer using SDL or ncurses (Planned)
gcc -std=c99 -Wall -I inc -o main.exe src/*.c
main.exe
cl /I inc /Fe:main.exe src\*.c
main.exe
gcc -std=c99 -Wall -I inc -o main src/*.c -lpthread
./main
Note:
-lpthread
is required for multithreading support.
Object-Oriented-C-Language/
βββ inc/ # Header files
β βββ algorithm.h
β βββ console.h
β βββ main.h
β βββ Scanner.h
β βββ System.h
β βββ thread.h
βββ src/ # Source files
β βββ algorithm.c
β βββ console.c
β βββ main.c
β βββ Scanner.c
β βββ System.c
β βββ thread.c
βββ translations/ # Translation files
β βββ ar.md # Arabic
β βββ es.md # Spanish
β βββ fr.md # French
β βββ hi.md # Hindi
β βββ it.md # Italian
β βββ ja.md # Japanese
β βββ ko.md # Korean
β βββ pt.md # Portuguese
β βββ ru.md # Russian
β βββ zh.md # Chinese
βββ LICENSE # License information
βββ README.md # Project description (this file)
- GCC (version β₯ 4.8)
- Make (optional)
# From the project root directory
gcc -std=c99 -Wall -I inc/ -o main src/*.c
CC = gcc
CFLAGS = -std=c99 -Wall -I inc
SRCS = $(wildcard src/*.c)
OBJS = $(SRCS:.c=.o)
TARGET = main
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f src/*.o $(TARGET)
# After build
./main
The sample will automatically create objects, invoke methods, and test threads.
-
SYSTEM out
out.printf(const string format, ...)
: Formatted outputout.println(const string format, ...)
: Formatted output with newline
-
SYSTEM in
in.read() -> int32_t
: Read a character as integer from stdin
-
File
-
Constructor:
File new_File(const string path, const string mode)
-
Methods:
f.scanf(const string format, ...)
: Formatted input from filef.printf(const string format, ...)
: Formatted output to filef.println(const string format, ...)
: Output with newlinef.open(const string path, const string mode)
: Open filef.close()
: Close filef.readLine() -> string
: Read one line from file
-
-
Time
-
Constructor:
Time new_Time(void)
-
Methods:
t.getSystemTime(Time* t)
: Get current system timet.getTime(Time* t)
: Get internal time valuet.setTime(...)
: Set time (year, month, day, hour, minute, second)t.start()
/t.stop()
: Timer thread control
-
-
Primitive Wrapper Constructors
-
new_String(string s)
- Methods:
s.length()
,s.charAt(index)
,s.substring(start, end)
,s.equals(...)
,s.toCharArray()
- Static:
String.valueOf(...)
,String.format(...)
- Methods:
-
new_Character(char c)
- Methods:
c.charValue()
,c.equals(...)
,Character.isDigit(char)
,Character.isLetter(char)
- Methods:
-
new_Byte(...)
,new_Short(...)
,new_Integer(...)
,new_Long(...)
,new_Float(...)
,new_Double(...)
,new_Boolean(...)
- Common methods:
x.getValue()
,x.toString()
,x.equals(...)
,x.compareTo(...)
- Static:
Wrapper.parse<Type>(...)
,Wrapper.valueOf(...)
- Byte-specific:
b.byteValue()
,b.toUnsigned()
,Byte.parseByte(string, base)
- Boolean-specific:
b.booleanValue()
,b.isTrue()
,b.isFalse()
,Boolean.parseBoolean(...)
- Common methods:
-
-
Thread
-
Constructor:
Thread new_Thread(void* (*function)(void*))
-
Methods:
start(...)
,join()
,detach()
,cancel()
,exit()
,delete()
-
-
Mutex
-
Constructor:
Mutex new_Mutex()
-
Methods:
lock()
,unlock()
,delete()
-
-
Console
-
Constructor:
Console new_console(void)
-
Methods:
print(...)
,println(...)
,readLine()
,clear()
setColor(ColorType color)
,resetColor()
,kbhit() -> int
-
-
Scanner
-
Constructor:
Scanner new_Scanner(struct __stdin_t in)
-
Methods:
nextChar()
,nextByte()
,nextShort()
,nextInt()
,nextLong()
nextUByte()
,nextUShort()
,nextUInt()
,nextULong()
nextBoolean()
,nextFloat()
,nextDouble()
,nextLDouble()
next() -> string
,nextLine() -> string
(By default, uses whitespace as delimiter and supports line reading.)
-
-
Stack
- Constructor:
Stack new_stack(size_t elementSize)
- Methods:
push(...)
,pop() -> void*
,clear()
,delete()
- Constructor:
-
Queue
- Constructor:
Queue new_queue(size_t elementSize)
- Methods:
push(...)
,pop() -> void*
,clear()
,delete()
- Constructor:
-
Deque
- Constructor:
Deque new_deque(size_t elementSize)
- Methods:
pushFront(...)
,pushBack(...)
,popFront()
,popBack()
,clear()
,delete()
- Constructor:
-
List
- Constructor:
List new_list(size_t elementSize)
- Methods:
add(...)
,get(index)
,remove(index)
,size()
,clear()
,delete()
- Constructor:
- Fork this project
- Create a feature branch:
git checkout -b feature/YourFeature
- Implement the feature
- Write tests and update docs
- Create a Pull Request
Please open an issue first to discuss your ideas before contributing.
This project is licensed under the MIT License.