I need to print an array[256x65536], I made a simple program but alway get error 2 if a=256 and b=65536.
Please help.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
typedef unsigned int WORD;
typedef WORD* WORDPTR;
WORDPTR *S;
WORDPTR D;
WORD x_num;
WORD y_num;
WORD a;
WORD b;
WORD i, j;
int main()
{
puts("------------------ Start --------------------");
puts("");
a = 0;
printf("Enter a = ");
scanf("%u", &a);
b = 0;
printf("Enter b = ");
scanf("%u", &b);
x_num = 1 << a;
y_num = 1 << b;
S = (WORDPTR *)malloc(x_num*sizeof(WORDPTR));
if (S == NULL)
{
puts("Error 1!");
return 1;
}
for (i = 0; i < x_num; i++)
{
S = (WORDPTR)malloc(y_num*sizeof(WORD));
if (S == NULL)
{
puts("Error 2!");
return 1;
}
}
D = (WORDPTR)malloc(y_num*sizeof(WORD));
if (D == NULL)
{
puts("Error 3!");
return 1;
}
puts("OK!");
return (0);
}
Please help.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
typedef unsigned int WORD;
typedef WORD* WORDPTR;
WORDPTR *S;
WORDPTR D;
WORD x_num;
WORD y_num;
WORD a;
WORD b;
WORD i, j;
int main()
{
puts("------------------ Start --------------------");
puts("");
a = 0;
printf("Enter a = ");
scanf("%u", &a);
b = 0;
printf("Enter b = ");
scanf("%u", &b);
x_num = 1 << a;
y_num = 1 << b;
S = (WORDPTR *)malloc(x_num*sizeof(WORDPTR));
if (S == NULL)
{
puts("Error 1!");
return 1;
}
for (i = 0; i < x_num; i++)
{
S = (WORDPTR)malloc(y_num*sizeof(WORD));
if (S == NULL)
{
puts("Error 2!");
return 1;
}
}
D = (WORDPTR)malloc(y_num*sizeof(WORD));
if (D == NULL)
{
puts("Error 3!");
return 1;
}
puts("OK!");
return (0);
}