Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<conio.h>
- #include<math.h>
- #define TRUE 1
- #define FALSE 0
- //functions declaration
- int init_matrix(int size);
- int main()
- {
- char **mat;
- int size, i,j;
- printf("please enter required size: ");
- scanf("%d", &size);
- init_matrix(size);
- // i want to check if the memory allocated by printing the mat.
- for (i = 0; i < size; i++)
- {
- for (j = 0; j < size; j++)
- {
- printf("%c", mat[i][j]);
- }
- printf("\n");
- }
- getch();
- return 0;
- }
- //gets a number from the user and allocates memory for the matrix.
- int init_matrix(int size)
- {
- int i,rows = size, cols = size, j;
- char **mat;
- mat = (char**)malloc(rows*sizeof(char));
- for (i = 0; i < rows; i++)
- {
- mat[i] = (char*)malloc(cols*sizeof(char));
- }
- if (mat == NULL)
- {
- printf("not enough memory");
- return FALSE;
- }
- for ( i = 0; i < rows; i++)
- {
- for ( j = 0; j < cols; j++)
- {
- mat[i][j] = 'o';
- }
- }
- return **mat;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement