diff --git a/OS/server b/OS/server new file mode 100644 index 0000000..2d7a7c1 Binary files /dev/null and b/OS/server differ diff --git a/OS/server.c b/OS/server.c new file mode 100644 index 0000000..6f18e74 --- /dev/null +++ b/OS/server.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include + +#define LINESIZE 128 + +void error(char *msg){ + perror(msg); + exit(1); +} + +int main (int argc, char *argv[]){ + int sockfd; + int newsockfd; + int portno; + int clilen; + int n; + char buffer[LINESIZE]; + struct sockaddr_in serv_addr; + struct sockaddr_in cli_addr; + if (argc < 2){ + fprintf(stderr, "ERROR, no port provided\n"); + exit(1); + } + + sockfd = socket(PF_INET, SOCK_STREAM, 0); + if (sockfd < 0){ + error("ERROR opening socket"); + } + + bzero((char *)&serv_addr, sizeof(serv_addr)); + portno = atoi(argv[1]); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(portno); + printf("Server is waiting for the message, please wait...\n"); + + if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof (serv_addr)) < 0){ + error("ERROR on binding"); + } + + listen(sockfd, 5); + clilen = sizeof(cli_addr); + + newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); + if (newsockfd < 0){ + error("ERROR on accept"); + } + bzero(buffer, LINESIZE); + n = read(newsockfd, buffer, LINESIZE); + if (n < 0){ + error("ERROR reading from socket"); + } + printf("The message is: %s", buffer); + fprintf(stderr, "The mesaage contains %d bytes.\n", n); + + close(sockfd); + + return 0; +} \ No newline at end of file diff --git a/a2/program b/a2/program new file mode 100644 index 0000000..dcebd64 Binary files /dev/null and b/a2/program differ diff --git a/a4/program b/a4/program new file mode 100644 index 0000000..4457898 Binary files /dev/null and b/a4/program differ diff --git a/a4/program.c b/a4/program.c index c0915b9..33b4fc5 100644 --- a/a4/program.c +++ b/a4/program.c @@ -2,8 +2,8 @@ #include #define LINESIZE 100 struct heap { - int* array; int size; + int* line; int capacity; }; @@ -21,7 +21,7 @@ int pravy_syn(int i){ struct heap* create_heap(int capacity){ struct heap* h = calloc(1,sizeof(struct heap)); - h->array = calloc(capacity,sizeof(int)); + h->line = calloc(capacity,sizeof(int)); h->capacity =capacity; h->size = 0; return h; @@ -37,7 +37,7 @@ void check_heap_property(struct heap* h){ break; } - if(h->array[i] > h->array[pravy] || h->array[i] > h->array[lavy]){ + if(h->line[i] > h->line[pravy] || h->line[i] > h->line[lavy]){ printf("%s\n","Niejekopa."); exit(0); } @@ -46,15 +46,15 @@ void check_heap_property(struct heap* h){ } void delete_heap(struct heap* h){ - free(h->array); + free(h->line); free(h); } -void swap(int arr[],int a, int b){ - int temp = arr[a]; - arr[a] = arr[b]; - arr[b] = temp; -} +//void vymen(int arr[],int a, int b){ +// int pom = arr[a]; +// arr[a] = arr[b]; +// arr[b] = pom; +//} void add(struct heap* h,int value){ @@ -64,7 +64,7 @@ void add(struct heap* h,int value){ } h->size += 1; - h->array[i] = value; + h->line[i] = value; } @@ -79,7 +79,7 @@ void print(struct heap* h,int count_spaces,int index){ for(int i =0;iarray[index]); + printf("%d\n",h->line[index]); print(h,count_spaces+1,lavy_syn(index)); print(h,count_spaces+1,pravy_syn(index)); @@ -91,24 +91,28 @@ void sort(struct heap *h){ int i = h->size-1; int p = parent(i); - while(h->array[i] < h->array[p]) { - swap(h->array,i, p); + while(h->line[i] < h->line[p]) { + int arr[] = h->line; + int pom = arr[i]; + arr[i] = arr[p]; + arr[p] = pom; + //vymen(h->line,i, p); i = parent(i); } } int main(){ - int i =0; - int temp_array[LINESIZE] = {0}; + int i = 0; + int temp_line[LINESIZE] = {0}; - while(scanf("%d",&temp_array[i]) == 1) { + while(scanf("%d",&temp_line[i])== 1) { i++; } struct heap* h = create_heap(i); for(int j =0;j +#include +#include "maze.h" + +void print_solution(char* matrix,int sz){ + for (int i = 0; i < sz * sz; i++){ + printf("%c ",matrix[i]); + if (i % sz == (sz-1)){ + printf("\n"); + } + } +} + +int main(){ + char tmaze[SZ+1][SZ+1]={ + "*x ", + " x ", + " x ", + " x ", + " ", + }; + char maze[SZ*SZ]; + memset(maze,' ',SZ*SZ); + for (int i= 0; i < SZ; i++){ + for (int j= 0; j < SZ; j++){ + if (tmaze[i][j] == 'x'){ + maze[i*SZ+j] = 'x'; + } + } + } + int r = solve_maze(maze,SZ); + if (!r){ + printf("Nenasiel som riesenie\n"); + } + print_solution(maze,SZ); + + return 0; +} diff --git a/sk1a/main.o b/sk1a/main.o new file mode 100644 index 0000000..330aa67 Binary files /dev/null and b/sk1a/main.o differ diff --git a/sk1a/maze.c b/sk1a/maze.c new file mode 100644 index 0000000..5f09bc8 --- /dev/null +++ b/sk1a/maze.c @@ -0,0 +1,8 @@ +#include +#include +#include "maze.h" +#include + +int solve_maze(char* maze,int size){ + return 0; +} diff --git a/sk1a/maze.h b/sk1a/maze.h new file mode 100644 index 0000000..2e34662 --- /dev/null +++ b/sk1a/maze.h @@ -0,0 +1,22 @@ +#ifndef _MAZEH +#define _MAZEH + +/** + * Funkcia by mala zobrať vstupnú mriežku a + * vyznačiť na nej cestu z ľavého horného rohu do pravého dolného rohu. + * Mriežka je uložená do jednorozmerného poľa, pričom najprv ide prvý riadok, + * za ním druhý a tak ďalej. + * + * Na mriežke sa nachádzajú znaky: + * ' ' - voľné miesto + * 'x' - stena. Stena nesmie byť prepísaná. + * '*' - poloha potkana. Na začiatku je na 0,0. + * + * @param maze Štvorcová mriežka rozmeru size x size. + * @param size Rozmer mriežky + * @return 1 ak existuje riešenie, 0 inak. + */ +int solve_maze(char* maze,int size); + + +#endif diff --git a/sk1a/maze.o b/sk1a/maze.o new file mode 100644 index 0000000..e73ecc2 Binary files /dev/null and b/sk1a/maze.o differ diff --git a/sk1a/program b/sk1a/program new file mode 100644 index 0000000..6045c16 Binary files /dev/null and b/sk1a/program differ