need help with array in C
-
I always get y_num=0 when a=16 and b=256 (I want y_num=65536) Please help.
#include #include #include #include #include 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[i] = (WORDPTR)malloc(y_num*sizeof(WORD)); if (S[i] == 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); }
My favorite site: Vietnam Trading Information Tour au Vietnam -
I always get y_num=0 when a=16 and b=256 (I want y_num=65536) Please help.
#include #include #include #include #include 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[i] = (WORDPTR)malloc(y_num*sizeof(WORD)); if (S[i] == 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); }
My favorite site: Vietnam Trading Information Tour au VietnamAS this is C, it can't be using .NET and therefore you are in the wrong forum. Try the visual C++ forum.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I always get y_num=0 when a=16 and b=256 (I want y_num=65536) Please help.
#include #include #include #include #include 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[i] = (WORDPTR)malloc(y_num*sizeof(WORD)); if (S[i] == 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); }
My favorite site: Vietnam Trading Information Tour au Vietnam -
The result of '1 << 256' is out range of WORD So what type of variable could solve this problem?
My favorite site: Vietnam Trading Information Tour au Vietnam
-
The result of '1 << 256' is out range of WORD So what type of variable could solve this problem?
My favorite site: Vietnam Trading Information Tour au Vietnam
1 - why aren't you asking in the right forum ? 2 - do you understand what a WORD is ? Tried to google it ? Compared it with other data types to see which seems like it's bigger ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )