fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 100
  4.  
  5. void read (int maze [][MAX]);
  6. int findPath (int maze[][MAX], int map[][MAX], int size);
  7. void print (int map [][MAX]);
  8.  
  9. int main()
  10. {
  11. int maze [][MAX] = {};
  12. int map [][MAX] = {};
  13.  
  14. int sum = 0;
  15. int size = MAX;
  16.  
  17. read (maze);
  18. findPath (maze, map,size);
  19. print (map);
  20.  
  21. return;
  22. }
  23.  
  24. void read (int maze[][MAX])
  25. {
  26. FILE * mazeFile;
  27. int num, r, c, count;
  28.  
  29. if ((mazeFile = fopen ("t4.txt", "r")) == NULL)
  30. {
  31. printf ("Error opening a file\n");
  32. }
  33. else
  34. {
  35. while (mazeFile != EOF)
  36. {
  37. fscanf (mazeFile, "%d", &maze[r][c]);
  38.  
  39. for (r = 0; r < 100 ; r++)
  40. {
  41. count = r + 1;
  42. for (c = 0; c <= count; c++)
  43. {
  44. printf ("(%d, %d) = %d\n",r, c, maze[r][c]);
  45. }
  46. }
  47. fclose (mazeFile);
  48. return;
  49. }
  50. }
  51. }
  52.  
  53. int findPath (int maze[][MAX], int map[][MAX], int size)
  54. {
  55. int sum [MAX][MAX] = {0};
  56. int row, col, maxNum;
  57.  
  58. for(row=(size-1); row >= 1; --row)
  59. {
  60. for (col-row;col>=1;--col)
  61. {
  62. maxNum = (sum[row+1][col] > sum [row+1][col+1] ? col : col + 1);
  63. sum[row][col]= maze[row][col] + sum [row+1][maxNum];
  64.  
  65. map[row][col] = maxNum;
  66. }
  67. }
  68. return sum [0][0];
  69. }
  70.  
  71. void print (int map [][MAX])
  72. {
  73. printf ("(%d, %d) = ", map[0][0], map[0][1]);
  74. return;
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:11:24: error: ISO C forbids empty initializer braces [-Werror=edantic]
prog.c:11:9: error: zero or negative size array ‘maze’
prog.c:12:24: error: ISO C forbids empty initializer braces [-Werror=edantic]
prog.c:12:9: error: zero or negative size array ‘map’
prog.c:21:5: error: ‘return’ with no value, in function returning non-void [-Werror]
prog.c:14:9: error: unused variable ‘sum’ [-Werror=unused-variable]
prog.c: In function ‘read’:
prog.c:35:25: error: comparison between pointer and integer [-Werror]
prog.c:27:9: error: unused variable ‘num’ [-Werror=unused-variable]
prog.c: In function ‘findPath’:
prog.c:55:5: error: missing braces around initializer [-Werror=missing-braces]
prog.c:55:5: error: (near initialization for ‘sum[0]’) [-Werror=missing-braces]
prog.c:60:9: error: statement with no effect [-Werror=unused-value]
cc1: all warnings being treated as errors
stdout
Standard output is empty