Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. char **Expand_maze_row(char **maze, int nrow, int ncol, int *rrow, int *rcol)
  2. {
  3. *rrow = *rcol = 0;
  4. char ** new_maze;
  5. int new_nrow = 2*nrow -1;
  6. printf("address of maze = %p\n",maze);
  7. new_maze = (char**)realloc(maze,new_nrow*ncol*sizeof(char*));
  8. printf("address of new_maze = %p\n",new_maze);
  9. new_maze[0] = (char*)malloc(new_nrow*ncol*sizeof(char));
  10. if(new_maze == NULL|| new_maze[0] == NULL)
  11. {
  12. *rrow = *rcol = 0;
  13. free(new_maze);
  14. return NULL;
  15. }
  16. else{
  17. int i,j;
  18. maze = new_maze;
  19. //assign address
  20. for(i = nrow; i<new_nrow;i++){
  21. maze[i] = &(maze[0][i*ncol]);
  22. }
  23. //test
  24. printf("address of maze = %p\n",maze);
  25. for(i = 0; i<(new_nrow); i++){
  26. printf("row# = %d\n",i);
  27. for(j = 0;j<ncol;j++){
  28. maze[i][j] = i+1;
  29. printf("%d ",maze[i][j]);
  30. }
  31. printf("\n");
  32. }
  33. printf("wtf");
  34. *rrow = new_nrow;
  35. *rcol = ncol;
  36. return new_maze;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement