commit 8aa0f3347c23281e104bb1531d5787b24ef5f814
parent c0c0fdca3dd50351c44526f0c371f4d4b54f6781
Author: Christos Margiolis <christos@margiolis.net>
Date: Wed, 15 Jan 2020 12:05:46 +0200
fixed makefiles
Diffstat:
10 files changed, 94 insertions(+), 55 deletions(-)
diff --git a/assignment-1.4-functions/hanoi-tower/Makefile b/assignment-1.4-functions/hanoi-tower/Makefile
@@ -2,30 +2,35 @@ EXEC = ht
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
-LDLIBS += -lm
+LDLIBS += -lm -lncurses
.PHONY: all clean
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC)
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.4-functions/menu/Makefile b/assignment-1.4-functions/menu/Makefile
@@ -2,30 +2,35 @@ EXEC = menu
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
-LDLIBS += -lm
+LDLIBS += -lm -lncurses
.PHONY: all clean
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC)
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.4-functions/sine-cos-taylor/Makefile b/assignment-1.4-functions/sine-cos-taylor/Makefile
@@ -2,30 +2,35 @@ EXEC = sct
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
-LDLIBS += -lm
+LDLIBS += -lm -lncurses
.PHONY: all clean
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC)
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/combinations/Makefile b/assignment-1.5-arrays-pointers-files/combinations/Makefile
@@ -2,30 +2,35 @@ EXEC = combs
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
-LDLIBS += -lm
+LDLIBS += -lm -lncurses
.PHONY: all clean
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC)
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/combinations/include/combinations.h b/assignment-1.5-arrays-pointers-files/combinations/include/combinations.h
@@ -28,4 +28,4 @@ int not_first_condition();
int not_second_condition_only();
int frequency();
-#endif
+#endif+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c
@@ -28,7 +28,7 @@ int get_k(int N)
do
{
- printf("N (6 < N <= 49): ");
+ printf("K: ");
scanf("%d", &K);
} while (K > N || K < 0);
@@ -58,25 +58,14 @@ int *fill_array(int N)
if (num >= 1 && num <= 49)
{
- if (i == 0)
- {
- *(arr + i) = num;
- i++;
- }
+ if (i == 0) { *(arr + i) = num; i++; }
else
{
- if (!exists_in_array(arr, N, num))
- {
- *(arr + i) = num;
- i++;
- }
- else
- printf("Give a different number.\n");
+ if (!exists_in_array(arr, N, num)) { *(arr + i) = num; i++; }
+ else printf("Give a different number.\n");
}
}
- else
- printf("Give a number in [1, 49].\n");
-
+ else printf("Give a number in [1, 49].\n");
} while (i < N);
}
@@ -130,17 +119,18 @@ void y_pair(int *y1, int *y2)
void combinations(int *arr, int x1, int x2, int y1, int y2)
{
- int i, j, temp;
-
- for (i = 1; i <= COMBSN; i++)
- {
- for (j = 0; j < COMBSN-1; j++)
- {
- temp = *(arr + j);
- *(arr + j) = *(arr + j + 1);
- *(arr + j + 1) = temp;
- }
- }
+ int i, j, k, l, m, n;
+
+ for (i=0; i < COMBSN-5; i++)
+ for (j = i+1; j < COMBSN-4; j++)
+ for (k = j+1; k < COMBSN-3; k++)
+ for (l = k+1; l < COMBSN-2; l++)
+ for (m= l+1; m < COMBSN-1; m++)
+ for (n = m+1; n < COMBSN; n++)
+ {
+ printf("%d %d %d %d %d %d", *(arr + i), *(arr + j), *(arr + k), *(arr + l), *(arr + m), *(arr + n));
+ printf("\n");
+ }
}
diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/main.c b/assignment-1.5-arrays-pointers-files/combinations/src/main.c
@@ -21,4 +21,4 @@ int main(int argc, char **argv)
free(arr);
return 0;
-}
+}+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/Makefile b/assignment-1.5-arrays-pointers-files/fcombinations/Makefile
@@ -1,31 +1,36 @@
-EXEC = combs
+EXEC = fcombs
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
-LDLIBS += -lm
+LDLIBS += -lm -lncurses
.PHONY: all clean
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC) ${ARGS}
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/Makefile b/assignment-1.5-arrays-pointers-files/minesweeper/Makefile
@@ -2,12 +2,15 @@ EXEC = minesweeper
SRC_DIR = src
OBJ_DIR = obj
+EXEC_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+MOVE = mv
MKDIR_P = mkdir -p
+CC = gcc
CPPFLAGS += -Iinclude
CFLAGS += -Wall
LDFLAGS += -Llib
@@ -18,14 +21,16 @@ LDLIBS += -lm -lncurses
all: $(EXEC)
$(EXEC): $(OBJ)
+ $(MKDIR_P) $(EXEC_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+ $(MOVE) $(EXEC) $(EXEC_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(MKDIR_P) $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
run:
- ./$(EXEC)
+ ./$(EXEC_DIR)/$(EXEC)
clean:
- $(RM) $(OBJ) $(EXEC)-
\ No newline at end of file
+ $(RM) $(OBJ) $(EXEC_DIR)/$(EXEC)+
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/notes.md b/assignment-1.5-arrays-pointers-files/notes.md
@@ -6,4 +6,21 @@
* meter function
* kcombinations
* combinations all in one with menu (6, k, file)
-* < >-
\ No newline at end of file
+* < >
+* ```c
+void comb(int a[], int N)
+{
+ int i, j, k, l, m, n;
+
+ for (i=0; i<N-5; i++)
+ for (j=i+1; j<N-4; j++)
+ for (k=j+1; k<N-3; k++)
+ for (l=k+1; l<N-2; l++)
+ for (m=l+1; m<N-1; m++)
+ for (n=m+1; n<N; n++)
+ {
+ printf("%d %d %d %d %d %d", a[i], a[j], a[k], a[l], a[m], a[n]);
+ printf("\n");
+ }
+}
+```+
\ No newline at end of file