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

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