commit 5498eb5bb195dfc4e541b6f5b8cd093a93b68bca
parent fb4c958b72e7d02eebf135293321140bd34d35d7
Author: Christos Margiolis <christos@margiolis.net>
Date: Thu, 9 Jan 2020 00:30:08 +0200
wrote some draft functions
Diffstat:
7 files changed, 94 insertions(+), 116 deletions(-)
diff --git a/assignment-1.5-arrays-pointers-files/README.md b/assignment-1.5-arrays-pointers-files/README.md
@@ -0,0 +1,31 @@
+# Assignment 1.5: Arrays - Pointers - Files
+
+**UNDER CONSTRUCTION, THE PROGRAMS DON'T WORK YET**
+
+## Execution
+
+* ```program_name``` = program's name
+* ```full_path/``` = full path
+* ```$``` = terminal command (__don't__ copy it)
+
+### Linux
+
+```shell
+$ cd full_path/assignment-1.5-arrays-pointers-files/program_name # combinations / minesweeper
+$ make
+$ make run
+$ make clean # optional
+```
+
+### Windows
+
+__Requirements:__ MinGW gcc compiler
+
+In CMD, do the following:
+
+```bat
+cd full_path/assignment-1.5-arrays-pointers-files/program_name
+make
+make run
+make clean
+```+
\ 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
@@ -10,9 +10,11 @@ bool exists_in_array(int *, int, int);
void x_pair(int *, int *);
void y_pair(int *, int *);
-void combinations(int *);
-int even_calc();
-int sum_calc();
+void combinations(int *, int, int, int, int);
+int even_calc(int *);
+bool belongs_x(int, int, int);
+int sum_calc(int *);
+bool belongs_y(int, int, int);
void print_combs();
int combinations_count(int);
int factorial(int);
@@ -22,6 +24,6 @@ float frequency();
char *get_filename();
bool is_subset();
-void read_file();
+void read_file(char *);
#endif
diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <string.h>
#include "combinations.h"
#define COMBSN 6
@@ -104,7 +105,7 @@ void y_pair(int *y1, int *y2)
}
-void combinations(int *arr)
+void combinations(int *arr, int x1, int x2, int y1, int y2)
{
int i, j, temp;
@@ -115,26 +116,64 @@ void combinations(int *arr)
temp = *(arr + j);
*(arr + j) = *(arr + j + 1);
*(arr + j + 1) = temp;
+
+ if (belongs_x(even_calc(arr), x1, x2) && belongs_y(even_calc(arr), x1, x2))
+ print_combs(arr);
}
}
}
-int even_calc()
+int even_calc(int *arr)
{
+ int i, numEven;
+
+ for (i = 0; i < COMBSN; i++)
+ {
+ if (*(arr + i) % 2 == 0)
+ numEven++;
+ }
+
+ return numEven;
+}
+
+bool belongs_x(int numEven, int x1, int x2)
+{
+ if (numEven >= x1 && numEven <= x2)
+ return true;
+ else
+ return false;
}
-int sum_calc()
+int sum_calc(int *arr)
{
+ int i, sum = 0;
+ for (i = 0; i < COMBSN; i++)
+ sum += *(arr + i);
+
+ return sum;
+}
+
+
+bool belongs_y(int sumNums, int y1, int y2)
+{
+ if (sumNums >= y1 && sumNums <= y2)
+ return true;
+ else
+ return false;
}
-void print_combs()
+void print_combs(int *arr)
{
+ int i;
+ for (i = 0; i < COMBSN; i++)
+ printf("%d", *(arr + i));
+ printf("\n");
}
@@ -179,7 +218,14 @@ float frequency()
char *get_filename()
{
+ char buffer[1000];
+ char *fileName;
+
+ fgets(buffer, 1000, stdin);
+ fileName = (char *)malloc(strlen(buffer) + 1);
+ strcpy(fileName, buffer);
+ return fileName;
}
@@ -189,7 +235,7 @@ bool is_subset()
}
-void read_file()
+void read_file(char *fileName)
{
-
+
}
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/main.c b/assignment-1.5-arrays-pointers-files/combinations/src/main.c
@@ -13,8 +13,9 @@ int main(int argc, char **argv)
K = get_val("K");
arr = fill_array(N);
x_pair(&x1, &x2);
+
y_pair(&y1, &y2);
- combinations(arr);
+ combinations(arr, x1, x2, y1, y2);
free(arr);
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h
@@ -4,16 +4,5 @@
#include <stdbool.h>
-extern bool gameOver;
-
-int set_width();
-int set_height();
-int set_mine_number();
-void init();
-void draw_table();
-void place_mines();
-void input();
-void logic();
-
#endif
\ No newline at end of file
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/main.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/main.c
@@ -5,20 +5,6 @@
int main(int argc, char **argv)
{
- int WIDTH = set_width();
- int HEIGHT = set_height();
- int MINE_NUMBER = set_mine_number();
- bool gameOver;
-
- init();
-
- if (!gameOver)
- {
- draw_table();
- place_mines();
- input();
- logic();
- }
return 0;
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c
@@ -3,82 +3,4 @@
#include <stdbool.h>
#include <time.h>
#include "minesweeper.h"
-#include "ccolors.h"
-
-
-int set_width()
-{
- int WIDTH;
-
- do
- {
- printf("Width (between 10 and 100): ");
- scanf("%d", &WIDTH);
- } while (WIDTH < 10 || WIDTH > 100);
-
-
- return WIDTH;
-}
-
-
-int set_height()
-{
- int HEIGHT;
-
- do
- {
- printf("Height (between 10 and 100): ");
- scanf("%d", &HEIGHT);
- } while (HEIGHT < 10 || HEIGHT > 100);
-
-
- return HEIGHT;
-}
-
-
-int set_mine_number()
-{
- int MINE_NUMBER;
-
- do
- {
- printf("Number of mines (between 1 and 20): ");
- scanf("%d", &MINE_NUMBER);
- } while (MINE_NUMBER <= 0 || MINE_NUMBER > 20);
-
-
- return MINE_NUMBER;
-}
-
-
-void init(int WIDTH, int HEIGHT)
-{
- bool gameOver = false;
-
- int mineX = rand() % WIDTH;
- int mineY = rand() % HEIGHT;
-}
-
-
-void draw_table(int WIDTH, int HEIGHT)
-{
-
-}
-
-
-void place_mines()
-{
-
-}
-
-
-void input()
-{
-
-}
-
-
-void logic()
-{
-
-}-
\ No newline at end of file
+#include "ccolors.h"+
\ No newline at end of file