/Morse-Code-Converter

A terminal-based Morse code converter tool for PC, implemented in both C and C++. The project demonstrates the use of threads, semaphores, and C/C++ programming features such as pointers and structs. This repository serves as a reference implementation for a similar project targeting microcontrollers.

Primary LanguageCMIT LicenseMIT

Morse Code Converter

Project Image

This is a simple Morse code converter program written in both C and C++. It allows you to convert text to Morse code and vice versa. Additionally, it supports custom Morse code mappings.

🛠️ Features

  • Convert text to Morse code.
  • Convert Morse code to text.
  • Support for custom Morse code mappings.

📁 Folder Structure (C and C++)

  • 📁 c_version
    • 📂 build
    • 📁 src
      • 📄 main.c
      • 📄 morse.c
      • 📄 morse.h
      • 📄 thread_utils.c
      • 📄 thread_utils.h
    • 📄 Makefile
    • 📄 morse_converter
  • 📁 cpp_version
    • 📂 build
    • 📁 src
      • 📄 main.cpp
      • 📄 morse.cpp
      • 📄 morse.h
      • 📄 thread_utils.cpp
      • 📄 thread_utils.h
    • 📄 Makefile
    • 📄 morse_converter

📋 Usage

Compilation in C

To compile the program, use the following command:

gcc -pthread -Wall src/main.cpp src/morse.cpp src/thread_utils.cpp -o morse_converter

Compilation in C++

To compile the program, use the following command:

g++ -pthread -Wall src/main.cpp src/morse.cpp src/thread_utils.cpp -o morse_converter

Compilation using Makefile

make

Execution

To run the program, use the following command:

./morse_converter

Command-line Arguments

  • -m2t <Morse code>: Convert Morse code to text.
  • -t2m <Text>: Convert text to Morse code.

Examples

Using Command-line Arguments

Convert Morse code to text:

./morse_converter -m2t "- .... ..."
Text: THS

Convert text to Morse code:

./morse_converter -t2m "THS"
Morse code: 
-
....
...

Without Command-line Arguments

./morse_converter
Choose an option:
1. Convert text to Morse code
2. Convert Morse code to text
Enter option (1 or 2): 1
Enter text to convert to Morse code: THS
Morse code: 
-
....
...
./morse_converter
Choose an option:
1. Convert text to Morse code
2. Convert Morse code to text
Enter option (1 or 2): 2
Enter Morse code to convert to text: - .... ...
Text: THS

Choose Custom Mapping Option

Project Image

../morse_converter A-.. B-.-. C..- D--.-Choose an option:
1. Convert text to Morse code
2. Convert Morse code to text
Enter option (1 or 2): 1
Enter text to convert to Morse code: ABC
Creating text-to-Morse thread...
Text-to-Morse thread created.
Thread entering semaphore...
Morse code: 
-..
-.-.
..-

Notes

  • Make sure to separate Morse code characters with spaces when providing input.

👨‍💻 Author

  • Paschalis M.

🤝 Contributing

Contributions to improve the project are welcome! Please feel free to fork the repository, make changes, and submit a pull request.

📜 License

This project is licensed under the MIT License.

  • License: MIT