Advertisement
AsafBenShabat

Untitled

Jan 4th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<conio.h>
  5. #include<math.h>
  6.  
  7. #define TRUE 1
  8. #define FALSE 0
  9.  
  10. //functions declaration
  11. int init_matrix(int size);
  12.  
  13.  
  14. int main()
  15. {
  16. char **mat;
  17. int size, i,j;
  18. printf("please enter required size: ");
  19. scanf("%d", &size);
  20. init_matrix(size);
  21.  
  22. // i want to check if the memory allocated by printing the mat.
  23. for (i = 0; i < size; i++)
  24. {
  25. for (j = 0; j < size; j++)
  26. {
  27. printf("%c", mat[i][j]);
  28. }
  29. printf("\n");
  30. }
  31.  
  32. getch();
  33. return 0;
  34. }
  35.  
  36. //gets a number from the user and allocates memory for the matrix.
  37. int init_matrix(int size)
  38. {
  39.  
  40. int i,rows = size, cols = size, j;
  41. char **mat;
  42. mat = (char**)malloc(rows*sizeof(char));
  43. for (i = 0; i < rows; i++)
  44. {
  45. mat[i] = (char*)malloc(cols*sizeof(char));
  46. }
  47. if (mat == NULL)
  48. {
  49. printf("not enough memory");
  50. return FALSE;
  51. }
  52. for ( i = 0; i < rows; i++)
  53. {
  54. for ( j = 0; j < cols; j++)
  55. {
  56. mat[i][j] = 'o';
  57. }
  58. }
  59. return **mat;
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement