Skip to content

sunwookim05/Object-Oriented-C-Language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Object-Oriented C Language

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 | ΰ€Ήΰ€Ώΰ€¨ΰ₯ΰ€¦ΰ₯€ | Ψ§Ω„ΨΉΨ±Ψ¨ΩŠΨ©


C GCC Make Makefile Windows Linux MACOS Git GitHub Vim VS VSCode CLion
Top Language Commits Last Commit Issues Open Pull Requests Closed Pull Requests Repo Size License Version Stars Forks Watchers

πŸ“– Overview

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.

βš™οΈ Key Features

  • 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

🧰 Tech Stack

Badge Description
C C Language: C99 standard, Object-Oriented Programming implementation using structs and function pointers
GCC GCC: GNU Compiler Collection, used for building C programs
Make Make: Build automation tool used for compiling and linking source files
Makefile Makefile: Configuration file used by Make for specifying build instructions
Windows Windows API: Windows system functions and multithreading support (windows.h, conio.h, process.h)
Linux Linux: Open-source operating system widely used in programming and development
MACOS macOS: Operating system used for Mac hardware with Unix-like commands
POSIX POSIX Threads: pthread.h, used for multithreading in Unix-based systems
Standard Lib C Standard Library: Core libraries including stdio.h, stdlib.h, string.h, time.h
OOP OOP in C: Encapsulation, abstraction, and polymorphism via structs and function pointers
Algorithms Algorithms: Implementations of data structures like stack, queue, deque, and list
Git Git: Version control system for managing code changes
GitHub GitHub: Platform for version control and collaboration, enabling sharing and review of code
Vim Vim: Highly configurable text editor for efficient text editing
Visual Studio Visual Studio: IDE for C/C++ development with powerful debugging, code analysis, and testing tools
VS Code Visual Studio Code: Source code editor used for writing and debugging
CLion CLion: JetBrains' C/C++ IDE, with powerful code analysis, refactoring, and CMake integration

πŸ–₯️ Platform Compatibility

This project has been tested and runs on the following platforms:

  • πŸͺŸ Windows 10 / 11
  • 🐧 Linux
  • 🍎 macOS

πŸ›£οΈ Roadmap

  • 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)

πŸ—οΈ OS-Specific Build Instructions

πŸͺŸ Windows (GCC MinGW)

gcc -std=c99 -Wall -I inc -o main.exe src/*.c
main.exe

πŸͺŸ Windows (MSVC Command Prompt)

cl /I inc /Fe:main.exe src\*.c
main.exe

🐧 Linux / 🍎 macOS

gcc -std=c99 -Wall -I inc -o main src/*.c -lpthread
./main

Note: -lpthread is required for multithreading support.

πŸ“‚ Directory Structure

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)

πŸ”§ Development & Build

Requirements

  • GCC (version β‰₯ 4.8)
  • Make (optional)

Manual Compilation

# From the project root directory
gcc -std=c99 -Wall -I inc/ -o main src/*.c

Sample Makefile

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)

πŸš€ How to Run

# After build
./main

The sample will automatically create objects, invoke methods, and test threads.

πŸ“‘ API Structure

1. System & Basic Types

  • SYSTEM out

    • out.printf(const string format, ...) : Formatted output
    • out.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 file
      • f.printf(const string format, ...) : Formatted output to file
      • f.println(const string format, ...) : Output with newline
      • f.open(const string path, const string mode) : Open file
      • f.close() : Close file
      • f.readLine() -> string : Read one line from file
  • Time

    • Constructor: Time new_Time(void)

    • Methods:

      • t.getSystemTime(Time* t) : Get current system time
      • t.getTime(Time* t) : Get internal time value
      • t.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(...)
    • new_Character(char c)

      • Methods: c.charValue(), c.equals(...), Character.isDigit(char), Character.isLetter(char)
    • 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(...)

2. Thread & Mutex

  • Thread

    • Constructor: Thread new_Thread(void* (*function)(void*))

    • Methods:

      • start(...), join(), detach(), cancel(), exit(), delete()
  • Mutex

    • Constructor: Mutex new_Mutex()

    • Methods:

      • lock(), unlock(), delete()

3. Console

  • Console

    • Constructor: Console new_console(void)

    • Methods:

      • print(...), println(...), readLine(), clear()
      • setColor(ColorType color), resetColor(), kbhit() -> int

4. Scanner

  • 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.)

5. Collections (Algorithm)

  • Stack

    • Constructor: Stack new_stack(size_t elementSize)
    • Methods: push(...), pop() -> void*, clear(), delete()
  • Queue

    • Constructor: Queue new_queue(size_t elementSize)
    • Methods: push(...), pop() -> void*, clear(), delete()
  • Deque

    • Constructor: Deque new_deque(size_t elementSize)
    • Methods: pushFront(...), pushBack(...), popFront(), popBack(), clear(), delete()
  • List

    • Constructor: List new_list(size_t elementSize)
    • Methods: add(...), get(index), remove(index), size(), clear(), delete()

πŸ› οΈ Contribution Guide

  1. Fork this project
  2. Create a feature branch: git checkout -b feature/YourFeature
  3. Implement the feature
  4. Write tests and update docs
  5. Create a Pull Request

Please open an issue first to discuss your ideas before contributing.

πŸ“„ License

This project is licensed under the MIT License.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages