This commit is contained in:
2024-05-05 00:42:55 +01:00
parent 1dd0393870
commit 635aa98a1a
9 changed files with 98 additions and 0 deletions

16
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"files.associations": {
"*.ejs": "html",
"stdio.h": "c"
}
}

3
Makefile Normal file
View File

@@ -0,0 +1,3 @@
build:
mkdir -p bin
clang -O3 -o bin/cargon $(shell find src -name '*.c') -lncurses -Wall -Wextra -Werror

BIN
bin/cargon Executable file

Binary file not shown.

View File

@@ -0,0 +1,21 @@
#include "cloneString.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* cloneString(const char* str) {
if (str == NULL) {
return NULL;
}
size_t len = strlen(str);
char* clone = malloc((len + 1) * sizeof(char));
if (clone == NULL) {
return NULL;
}
strcpy(clone, str);
return clone;
}

View File

@@ -0,0 +1,8 @@
#ifndef CLONESTRING_H
#define CLONESTRING_H
#include <stdlib.h>
char* cloneString(const char* str);
#endif // CLONESTRING_H

21
src/main.c Normal file
View File

@@ -0,0 +1,21 @@
#include "cloneString/cloneString.h"
#include <stdio.h>
#include <stdlib.h>
int main() {
const char* str = "Hello, World!";
char* clone = cloneString(str);
if (clone == NULL) {
printf("Failed to clone string\n");
return 1;
}
printf("Original string: %s\n", str);
printf("Cloned string: %s\n", clone);
free(clone);
return 0;
}

9
src/number/number.c Normal file
View File

@@ -0,0 +1,9 @@
#include "number.h"
#include <string.h>
struct number translateNumber(char *code) {
struct number num;
num.sign = code[0] == '-' ? 1 : 0;
return num;
}

14
src/number/number.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef NUMBER_H
#define CLONESTRING_HNUMBER_H
#include <stdint.h>
struct number {
uint8_t sign;
uint64_t numerator;
uint64_t denominator;
};
struct number translateNumber(char *code);
#endif // NUMBER_H