This line fails:
Code:
#include "windows.h"
#include "stdio.h"
#include "time.h"
#include "math.h"
#include "string.h"
typedef struct UNIT{
void **p;
int pS;
}UNIT;
UNIT **u;
int uS=10;
int L1,L2;
void main(void){
u=malloc(uS*sizeof(UNIT *));
printf("\nu=malloc succeeded");
if(u==NULL){
printf("\n\nu=malloc failed");
return;
}
printf("\nfor(L1){");
for(L1=0;L1<uS;L1++){
u[L1]->pS=10; // it says "u[L1]->pS= <bad address 0xbaadf011>" in the debugger
printf("\n\tu[%d]->p",L1);
u[L1]->p=malloc(u[L1]->pS*sizeof(void *));
printf(" = malloc");
if(u[L1]->p==NULL){
printf(" \tFAILED");
continue;
}else{
printf(" succeeded");
}
printf("\n\tfor(L2){");
for(L2=0;L2<u[L1]->pS;L2++){
printf("\n\t\tu[%d]->p[%d]",L1,L2);
u[L1]->p[L2]=malloc(64);
printf(" = malloc");
if(u[L1]->p[L2]==NULL){
printf(" \tFAILED");
continue;
}else{
printf(" succeeded");
}
((char *)u[L1]->p[L2])[0]='p';
}
printf("\n\t}");
}
printf("\n}");
printf("\nWhy doesn't this print?");
printf("\na thing = %c",(((char *)u[3]->p[3])[0]));
for(L1=0;L1<uS;L1++){
for(L2=0;L2<u[L1]->pS;L2++){
free(u[L1]->p[L2]);
}
free(u[L1]->p);
}
free(u);
}