Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. need help with array in C

need help with array in C

Scheduled Pinned Locked Moved Managed C++/CLI
helpcomdata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ndtoan13
    wrote on last edited by
    #1

    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

    C J 2 Replies Last reply
    0
    • N ndtoan13

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      AS 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 )

      1 Reply Last reply
      0
      • N ndtoan13

        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

        J Offline
        J Offline
        Jude Deng
        wrote on last edited by
        #3

        The result of '1 << 256' is out range of WORD. 1 << 256 equal to 2^256! 65536 = 2^16

        N 1 Reply Last reply
        0
        • J Jude Deng

          The result of '1 << 256' is out range of WORD. 1 << 256 equal to 2^256! 65536 = 2^16

          N Offline
          N Offline
          ndtoan13
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • N ndtoan13

            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

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            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 )

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups