Hi I want to get some strings from user then put those in 2D array and at the end just print every character position in array for test.(Im writing at visual studio 2017) but I'm getting output like this for example:
marray[1][2]==
marray[1][3]==
marray[1][3]==
and I'm getting this for all cells. and here is my code so far:
#include <stdio.h>
#include <stdlib.h>
void inputnames(char**, int, int);
void printitems(char**, int, int);
int main(void)
{
int m;
const int n = 30; //students name limit
printf("Enter Number of students:");
scanf_s("%d ", &m); //getting row size from user
//---------------------------------------------
char** p;
p = (char**)malloc(sizeof(char)*m);
for (int i = 0; i < m; i++)
{ //this part for allocating 2d array
p[i] = (char*)malloc(sizeof(char)*n);
}
//--------------------------------------------
inputnames(p, m, n); //filling 2D array
printitems(p, m, n); //print each character with position for test
getchar();
}
void inputnames(char** marray, int mm, int nn)
{
int i = 0, j = 0;
for (i = 0; i<mm; i++)
{
while (marray[i][j] != '\n' && j<nn)
{
scanf_s("%c", &marray[i][j]);
}
}//end of for i
}
void printitems(char** marray, int mm, int nn) //this function is for test
{
int i = 0, j = 0;
for (i = 0; i<mm; i++)
{
for (j = 0; j<nn; j++)
{
printf("marray[%d][%d]=%c\n",i,j,marray[i][j]);
}//end of for j
}//end of for i
}