labsolve.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include <limits.h>
  6. #include <assert.h>
  7. #define MAXCOLS 256
  8. #define MAXROWS 256
  9. /* Data type: Labyrinth - ASCII map, costs, direction */
  10. typedef struct labyrinth
  11. {
  12. char lab[MAXCOLS+2][MAXROWS];
  13. long costs[MAXCOLS][MAXROWS];
  14. long bestx[MAXCOLS][MAXROWS];
  15. long besty[MAXCOLS][MAXROWS];
  16. int maxrow;
  17. int startx;
  18. int starty;
  19. int treasurex;
  20. int treasurey;
  21. }LabCell, *Lab_p;
  22. //prototypes
  23. Lab_p LabRead(File* in);
  24. int main(int argc, char* argv[])
  25. {
  26. FILE *in = stdin;
  27. Lab_p lab = NULL, handle;
  28. char* inp;
  29. if(argc > 2)
  30. {
  31. fprintf(stderr, "Usage: %s [<file>]\n", argv[0]);
  32. exit(EXIT_FAILURE);
  33. }
  34. if(argc == 2)
  35. {
  36. in = fopen(argv[1], "r");
  37. if(!in)
  38. {
  39. perror(argv[0]);
  40. exit(EXIT_FAILURE);
  41. }
  42. }
  43. lab LabRead(in);
  44. return 0;
  45. }
  46. Lab_p LabRead(File* in)
  47. {
  48. int x,y = 0;
  49. char value;
  50. Lab_p map = malloc(LabCell);
  51. while(*in)
  52. {
  53. while(value = fgetc(*in) != "\n")
  54. {
  55. map->lab[x] = value;
  56. }
  57. }
  58. }
  59. }