#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char **pps;
int i, n = 10;
char name[256];
pps = (char **)calloc(n,sizeof(char **));
for (i=0; i<n; i++)
{
printf("\n Enter name[%d]: ",i+1);
gets(name);
printf("\n Name=%s len=%d",name,strlen(name)+1 );
pps[i] = (char *)malloc(strlen(name)+1);
printf("\n pps[i]=%u",pps[i]);
if (pps[i] = NULL)
{
perror("\nerror in malloc");
exit(1);
}
printf("\n pps[i]=%u",pps[i]);
strncpy(pps[i],name,strlen(name)+1);
}
}
/* input/output from program: Enter name[1]: abcdef
Name=abcdef len=7
pps[i]=13311184
pps[i]=0
*/
The program gives Runtime Error ??? Please help to find what is wrong and why PPS[i] become currupted ??? I am using visual studio 2010
printfbetween your failingmallocand the relatedperror. (printfmay changeerrnoand make theperrorless than useless.)if (pps[i] = NULL)should give you a warning! Or if you already got a warning, then consider not ignoring the warnings, but actually fixing them... They're there for a reason!