Compare commits
11 Commits
3a07a9b5ed
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 957177e9ec | |||
| c9e69ededb | |||
| 2f6bba5ce7 | |||
| 0d5a86a158 | |||
| e55dd2bf96 | |||
| ed13b8d624 | |||
| f9a5352b6e | |||
| 08e39eca09 | |||
| fbe0514d1b | |||
| 6bbd07c028 | |||
| ccd43f25c7 |
@@ -0,0 +1,15 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../libs/string.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
string test = strInit("Hello?");
|
||||||
|
printf("String now: %s\n", test);
|
||||||
|
strAdd(&test, " World?");
|
||||||
|
printf("String now: %s\n", test);
|
||||||
|
strSet(&test, "Another intresting test with string");
|
||||||
|
printf("String now: %s\n", test);
|
||||||
|
free(test);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+3
-2
@@ -2,11 +2,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "../libs/threads.h"
|
#include "../libs/threads.h"
|
||||||
|
#include "../libs/time.h"
|
||||||
|
|
||||||
void* task() {
|
void* task() {
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("Background task running\n");
|
printf("Background task running\n");
|
||||||
wait(1);
|
wait(1000);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -16,7 +17,7 @@ int main() {
|
|||||||
start_thread(&thread_handle, task);
|
start_thread(&thread_handle, task);
|
||||||
|
|
||||||
printf("Main program continues\n");
|
printf("Main program continues\n");
|
||||||
wait(5);
|
wait(5000);
|
||||||
|
|
||||||
kill_thread(thread_handle);
|
kill_thread(thread_handle);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("Wait 5 seconds...\n");
|
printf("Wait 5 seconds...\n");
|
||||||
wait(5);
|
wait(5000);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// It's base. NUL terminator.
|
||||||
|
int nulTerm = 1;
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// BASE - String and init of this
|
||||||
|
// -------------------------------------
|
||||||
|
typedef char* string;
|
||||||
|
string strInit(char* s) {
|
||||||
|
string str = malloc(strlen(s) + nulTerm);
|
||||||
|
strcpy(str, s);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
void strResize(string* s, int new_size) {
|
||||||
|
*s = realloc(*s, new_size + nulTerm);
|
||||||
|
}
|
||||||
|
// -------------- END ------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// FUNCTION - basic operations
|
||||||
|
// -------------------------------------
|
||||||
|
void strAdd(string* s, char* str_new) {
|
||||||
|
*s = realloc(*s, strlen(*s) + strlen(str_new) + nulTerm);
|
||||||
|
strcat(*s, str_new);
|
||||||
|
}
|
||||||
|
void strSet(string* s, char* str_new) {
|
||||||
|
*s = realloc(*s, strlen(str_new) + nulTerm);
|
||||||
|
strcpy(*s, str_new);
|
||||||
|
}
|
||||||
|
void strCopy(string* dst, string* src) {
|
||||||
|
strcpy(*dst, *src);
|
||||||
|
}
|
||||||
|
// -------------- END ------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// CONVERT - different convert to str
|
||||||
|
// -------------------------------------
|
||||||
|
int numLen(double num) {
|
||||||
|
return snprintf(NULL, 0, "%lf", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* int2Str(int* num) {
|
||||||
|
char* buffer = malloc(numLen(*num) + nulTerm);
|
||||||
|
sprintf(buffer, "%d", *num);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
char* float2Str(float* num) {
|
||||||
|
char* buffer = malloc(numLen(*num) + nulTerm);
|
||||||
|
sprintf(buffer, "%f", *num);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
char* double2Str(double* num) {
|
||||||
|
char* buffer = malloc(numLen(*num) + nulTerm);
|
||||||
|
sprintf(buffer, "%lf", *num);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
// -------------- END ------------------
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "time.h"
|
|
||||||
|
|
||||||
void start_thread(void** thread_handle, void* (*task)(void*)) {
|
void start_thread(void** thread_handle, void* (*task)(void*)) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|||||||
+4
-2
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
@@ -6,8 +8,8 @@
|
|||||||
|
|
||||||
void wait(int time) {
|
void wait(int time) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep(time*1000);
|
Sleep(time);
|
||||||
#else
|
#else
|
||||||
sleep(time);
|
usleep(time * 1000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user