Hi people I created an array that is two-dimensional dynamically. I want to determine which row empty but my syntax knowledge is insufficient. Thank you in advance for your interest.
There is my code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i,j,*x,y=0;
int** p=malloc(sizeof(int*)*4);
for(i=0;i<3;i++)
p[i]=malloc(sizeof(int)*3);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
p[i][j]=(y++);
}
x=NULL;
for(i=0;i<4;i++)
{
// Fourth index shouldn't be NULL?
if(p[i]==x)
printf("NULL");
else
printf("Not null");
}
for(i=0;i<4;i++)
free(p[i]);
free(p);
return(0);
}
Aucun commentaire:
Enregistrer un commentaire