Compare commits

..

No commits in common. "ff80b3a4383fa32f7406c7ffed4f210843af3cc5" and "8e458dd08e92e010a37ef961b75d01ef0615e22c" have entirely different histories.

3 changed files with 27 additions and 24 deletions

10
.gitignore vendored
View File

@ -52,13 +52,3 @@ Module.symvers
Mkfile.old Mkfile.old
dkms.conf dkms.conf
#CMake
cmake_install.cmake
CMakeFiles
CMakeCache.txt
Makefile
#execs
garland

View File

@ -1,5 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(garland VERSION 1.0 LANGUAGES C)
add_executable(garland main.c)

36
main.c
View File

@ -2,16 +2,14 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#define YELLOW "\033[1;33m#" #define YELLOW "\033[1;33m"
#define RED "\033[1;31m#" #define RED "\033[1;31m"
#define BLUE "\033[1;34m#" #define BLUE "\033[1;34m"
#define GREEN "\033[1;32m#" #define GREEN "\033[1;32m"
#define RESET "\033[0m" #define RESET "\033[0m"
static char* lightbulbs[] = {RED, YELLOW, BLUE, GREEN};
typedef struct Garland { typedef struct Garland {
char* lightbulbs; char** lightbulbs;
unsigned int length; unsigned int length;
} Garland; } Garland;
@ -28,14 +26,34 @@ Garland generate_garland(unsigned int length) {
g.lightbulbs = malloc(length * sizeof(char*)); g.lightbulbs = malloc(length * sizeof(char*));
g.length = length; g.length = length;
for (unsigned int i = 0; i < length; i ++) { for (unsigned int i = 0; i < length; i ++) {
g.lightbulbs[i] = rand() % 4; char* color = (char*) malloc(9);
switch (rand() % 4) {
case 0:
strncpy(color, RED, 7);
break;
case 1:
strncpy(color, YELLOW, 7);
break;
case 2:
strncpy(color, GREEN, 7);
break;
case 3:
strncpy(color, BLUE, 7);
break;
}
strncpy(color+7, "#\0", 2);
g.lightbulbs[i] = malloc(9);
strncpy(g.lightbulbs[i], color, 9);
free(color);
color = NULL;
} }
return g; return g;
} }
void print_garland(Garland* g) { void print_garland(Garland* g) {
for (unsigned int i = 0; i < g->length; i ++) { for (unsigned int i = 0; i < g->length; i ++) {
printf("%s", lightbulbs[g->lightbulbs[i]]); printf("%s", g->lightbulbs[i]);
} }
printf(RESET); printf(RESET);
printf("\n"); printf("\n");