diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 23b9be0..15b16ad --- a/README.md +++ b/README.md @@ -1 +1,44 @@ -# easyc \ No newline at end of file +# Easy C +![Version](https://img.shields.io/badge/version-v1.0.0-red) +![Publisher](https://img.shields.io/badge/publisher-YasTech-blue) +![Developer](https://img.shields.io/badge/developer-Hossein%20Araghi-white) +### Navigation +1. What is Easy C? +2. Why we should use Easy C? +3. Usage of Easy C +4. Reference of Easy C +5. Last changes +### What is Easy C? +Easy C is c library base on CMake, and it contains many of functions and data types to make your code easy, fast and standard. You can simply use it in your project with CMake. +### Why we should use Easy C? +- Have a cleaner code +- Make things easier +- Do things standard +- Faster and better app +### Usage of Easy C +- First clone library to your project +- Second Add Library to your `CMakeLists.txt` +```cmake +# if you are using sub directories +# add_subdirectory(lib/easyc) + +# add library to your project +# put your project name instead of *main* +target_link_libraries(main PRIVATE easyc) +``` +### Reference of Easy C +| Name | Type | Description | Args | +| --------------- | --------- | --------------------------------------- | ----------- | +| string | data type | Replacement for characters | | +| getString | function | Get a string input from the system | string q | +| getInt | function | Get a string input from the system | string q | +| getDouble | function | Get a double input from the system | string q | +| getFloat | function | Get a float input from the system | string q | +| getChar | function | Get a char input from the system | string q | +| getLong | function | Get a long input from the system | string q | +| print | function | print string without \n | string text | +| println | function | print string with \n | string text | +| intToString | function | convert int to string | int number | +| copyToString | function | copy string to new string and return it | string text | +| uppercaseChar | function | make character uppercase | char c | +| uppercaseString | function | make string uppercase | string text | \ No newline at end of file diff --git a/easyc.c b/easyc.c new file mode 100755 index 0000000..65a23d0 --- /dev/null +++ b/easyc.c @@ -0,0 +1,144 @@ +/* + title : Easy C Library + copyright : Copyright 2021 YasTech.org | All Right Reserved + developer : Hossein Araghi + url : https://yastech.org + version : 1.0.0 +*/ + +#include "easyc.h" + +// get string value +string getString(string q) +{ + printf("%s", q); + string a = NULL; + scanf("%ms", &a); + return a; +} + +// get int value +int getInt(string q) +{ + printf("%s", q); + string str; + string ptr; + long a; + scanf("%ms", &str); + a = strtol(str, &ptr, 10); + return (int) a; +} + +// get double value +double getDouble(string q) +{ + printf("%s", q); + string str; + string ptr; + long a; + scanf("%ms", &str); + a = strtol(str, &ptr, 10); + return (double) a; +} + +// get float value +float getFloat(string q) +{ + printf("%s", q); + string str; + string ptr; + long a; + scanf("%ms", &str); + a = strtol(str, &ptr, 10); + return (float) a; +} + +// get char value +char getChar(string q) +{ + printf("%s", q); + char a; + scanf("%c", &a); + return a; +} + +// get long value +long getLong(string q) +{ + printf("%s", q); + string str; + string ptr; + long a; + scanf("%ms", &str); + a = strtol(str, &ptr, 10); + return a; +} + +// usual print +void print(string text) +{ + printf("%s", text); +} + +// print with new line +void println(string text) +{ + printf("%s\n", text); +} + +// Convert Int To String +string intToString(int number) +{ + string c = malloc(5); + sprintf(c, "%d", number); + return c; +} + +// Convert Long To String +/*string longToString(long number) +{ + string c = malloc(20); + sprintf(c, "%d", number); + return c; +}*/ + +// Copy String +string copyToString(string text) +{ + + int length = (int) strlen(text); + string copy = malloc(length + 1); + for (int i = 0; i < length + 1; i++) + { + copy[i] = text[i]; + } + return copy; +} + +// Upper Case Letter +char uppercaseChar(char c) +{ + if(c > 96 && c < 123) + { + return (char) ((int) c - 32); + } else + { + return c; + } +} + +// Upper Case String +string uppercaseString(string text) +{ + string output = malloc(strlen(text) + 1); + for (int i = 0; i < strlen(text); i++) { + if(text[i] > 96 && text[i] < 123) + { + output[i] = (char) ((int) text[i] - 32); + } else + { + output[i] = text[i]; + } + } + return output; +} diff --git a/easyc.h b/easyc.h new file mode 100755 index 0000000..1021b51 --- /dev/null +++ b/easyc.h @@ -0,0 +1,59 @@ +/* + title : Easy C Library + copyright : Copyright 2021 YasTech.org | All Right Reserved + developer : Hossein Araghi + url : https://yastech.org + version : 1.0.0 +*/ + +#ifndef EASY_C_H +#define EASY_C_H + +// Includes +#include +#include +#include + +// Define Type String +typedef char* string; + +// get string value +extern string getString(string q); + +// get int value +extern int getInt(string q); + +// get double value +extern double getDouble(string q); + +// get float value +extern float getFloat(string q); + +// get char value +extern char getChar(string q); + +// get long value +extern long getLong(string q); + +// usual print +extern void print(string text); + +// print with new line +extern void println(string text); + +// Convert Int To String +extern string intToString(int number); + +// Convert Long To String +// extern string longToString(long number); + +// Copy String +extern string copyToString(string text); + +// Upper Case Letter +extern char uppercaseChar(char c); + +// Upper Case String +extern string uppercaseString(string text); + +#endif //EASY_C_H