Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. // proj3.c
  2. // IZP
  3. // Created by Patrik Smola on 06/12/2019.
  4. // xsmola08
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10.  
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. // FUNCTIONS PROTOTYPES //
  13. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14.  
  15. //void getMatrix(int rows, int cols, FILE *fp);
  16. //bool isborder(Map *map, int r, int c, int border);
  17.  
  18. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. // MAIN //
  20. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  21.  
  22. typedef struct{
  23. int rows;
  24. int cols;
  25. unsigned char *cells;
  26. } Map;
  27.  
  28. int main(int argc, char *argv[]){
  29.  
  30. Map mapa;
  31. mapa.rows = atoi(argv[2]);
  32. mapa.cols = atoi(argv[3]);
  33.  
  34. if (argc > 5)
  35. fprintf(stderr,"Invalid number of arguments.\n");
  36.  
  37.  
  38. /* a = getopt_long(argc, argv, "help:test:lhand:rhand");
  39. if (a == -1)
  40. break;
  41. switch(a){
  42. case 'help'
  43. fprintf(stdout,"Napoveda");
  44. break;
  45.  
  46. case 'test'
  47. testMap;
  48. break;
  49.  
  50. case 'lhand'
  51. int leftHand;
  52. break;
  53.  
  54. case 'rhand'
  55. int rightHand;
  56. break;
  57. default;
  58. }*/
  59. FILE *fp = fopen("bludiste.txt", "r");
  60. mapa.cells=malloc(sizeof(unsigned char)*mapa.rows*mapa.cols);
  61. for(int i = 0; i < mapa.rows*mapa.cols; i++){
  62. char c=fgetc(fp);
  63. if(c!=' ' && c!= '\n'){
  64. mapa.cells[i]=c;
  65. }
  66. else{
  67. i--;
  68. }
  69. printf("nacitanie do %d\n", i);
  70. // fscanf(fp, "%s", &mapa.cells[i]);
  71.  
  72. }
  73. printf("medzi for \n");
  74. //for(int i = 0; i < mapa.rows*mapa.cols-1; i++){
  75.  
  76. printf("%s \n", mapa.cells);
  77. //printf("vypisanie do %d\n", i);
  78. //}
  79. printf("fin\n");
  80. fclose(fp);
  81. return 0;
  82. }
  83.  
  84.  
  85. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  86. // FUNCTION DEFINITIONS //
  87. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88.  
  89.  
  90. /*void getMatrix(int rows, int cols, FILE *fp){
  91. for(int i = 0; i < rows; i++){
  92. for(int j = 0; j < cols; j++){
  93. cells[i][j] = fscanf(fp);
  94. }
  95. }
  96. for(int i = 0; i < rows; i++){
  97. for(int j = 0; j < cols; j++){
  98. printf("%u ", cells[i][j]);
  99. }
  100. }
  101. }
  102. */
  103. /*bool isborder(Map *map, int r, int c, int border){
  104. switch (border) {
  105. case 1:
  106. if (map.cells[map.cols*(r-1)+c] == (1 || 3 || 5 || 7)) {
  107. return true;
  108. }else{
  109. return false;}
  110. break;
  111. case 2:
  112. if (map.cells[map.cols*(r-1)+c] == (2 || 3 || 6 || 7)) {
  113. return true;
  114. }else{
  115. return false;}
  116. break;
  117. case 3:
  118. if (map.cells[map.cols*(r-1)+c] == (4 || 5 || 7 || 6)) {
  119. return true;
  120. }
  121. else{
  122. return false;}
  123. break;
  124. default:
  125. break;
  126. }
  127. }*/
  128.  
  129. //void leftHand()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement