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. Visual Studio
  4. BYTE ARRAY VALUE

BYTE ARRAY VALUE

Scheduled Pinned Locked Moved Visual Studio
questionc++data-structurescollaborationhelp
6 Posts 2 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.
  • A Offline
    A Offline
    anne_rose
    wrote on last edited by
    #1

    Hi , Currently doing a project in VC++ (2012) and I have declared a BYTE array i.e BYTE _iDATA[] = { 0x01,0x02,0x03,0x02 }; I pass this variable as a PARAMETER in a function ie BYTE _iDATA[] = { 0x01,0x02,0x03,0x0 }; getRepo(01,iDATA); then the iDATA value as to change, so i create one more new BYTE ARRAY BYTE _cDATA[] = { 0x0A,0xBC,0x03,0xA0 }; getRepo(01,cDATA); I CANNOT USE THE SAME BYTE ARRAY VARIABLE. So if i have to pass 10 diff values to a function, i have to declare 10 byte array variables. How to maintain a single BYTE array variable and reuse it. I tried some conversion method but the function getRepo demands parameter as BYTE[] which cannot be changed due to code restriction from other team. How can i resolve this issue? Thanks Anne void getRepo(unsigned int iNO, BYTE[] userDATA) { }

    L 1 Reply Last reply
    0
    • A anne_rose

      Hi , Currently doing a project in VC++ (2012) and I have declared a BYTE array i.e BYTE _iDATA[] = { 0x01,0x02,0x03,0x02 }; I pass this variable as a PARAMETER in a function ie BYTE _iDATA[] = { 0x01,0x02,0x03,0x0 }; getRepo(01,iDATA); then the iDATA value as to change, so i create one more new BYTE ARRAY BYTE _cDATA[] = { 0x0A,0xBC,0x03,0xA0 }; getRepo(01,cDATA); I CANNOT USE THE SAME BYTE ARRAY VARIABLE. So if i have to pass 10 diff values to a function, i have to declare 10 byte array variables. How to maintain a single BYTE array variable and reuse it. I tried some conversion method but the function getRepo demands parameter as BYTE[] which cannot be changed due to code restriction from other team. How can i resolve this issue? Thanks Anne void getRepo(unsigned int iNO, BYTE[] userDATA) { }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Before calling your function just change the values in the array to whatever you need, like:

      BYTE myData[] = { 0x01,0x02,0x03,0x0 };
      getRepo(1, myData);

      myData[0] = 0x0A;
      myData[1] = 0xBC;
      // ... etc
      getRepo(1, myData);

      Veni, vidi, abiit domum

      A 1 Reply Last reply
      0
      • L Lost User

        Before calling your function just change the values in the array to whatever you need, like:

        BYTE myData[] = { 0x01,0x02,0x03,0x0 };
        getRepo(1, myData);

        myData[0] = 0x0A;
        myData[1] = 0xBC;
        // ... etc
        getRepo(1, myData);

        Veni, vidi, abiit domum

        A Offline
        A Offline
        anne_rose
        wrote on last edited by
        #3

        Thank you Richard, it worked .. Since myDATA is of variable size , I created a function for it. I have created a "extern int counter " under a header file (h1.h) the under main.cpp, i include h1.h and also i declare int counter; main() { counter=0; CallFun1(); counter=1; CallFun2(); CallFun3(); } submodule.cpp #include h1.h CallFun2() { if (counter==0) ... else ... } CallFun3() { if (counter==0) ... else ... } Now for CallFun1(), the counter is 1 and once the control goes back to main.cpp, the counter becomes 0 and results in many errors. in main.cpp, once CallFun1() is called, the counter SHOULD be 1 and never change. But here it reverts to old value as 0. Where is the error in my code? Thanks once again....

        L 1 Reply Last reply
        0
        • A anne_rose

          Thank you Richard, it worked .. Since myDATA is of variable size , I created a function for it. I have created a "extern int counter " under a header file (h1.h) the under main.cpp, i include h1.h and also i declare int counter; main() { counter=0; CallFun1(); counter=1; CallFun2(); CallFun3(); } submodule.cpp #include h1.h CallFun2() { if (counter==0) ... else ... } CallFun3() { if (counter==0) ... else ... } Now for CallFun1(), the counter is 1 and once the control goes back to main.cpp, the counter becomes 0 and results in many errors. in main.cpp, once CallFun1() is called, the counter SHOULD be 1 and never change. But here it reverts to old value as 0. Where is the error in my code? Thanks once again....

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Firstly please format your code properly by using <pre> tags around it (see the "code" button above the edit box). That makes it so much easier to read as I have done below. Secondly, your design is really not the best way to do it. It is much better to use proper parameters to your functions and control those parameters from the caller, like:

          main()
          {
          counter=0;
          CallFun1(counter);
          counter=1;
          CallFun2(counter);
          CallFun3(counter);
          }

          // submodule.cpp
          CallFun2(int counter)
          {
          if (counter==0)
          ...
          else
          ...
          }

          CallFun3(int counter)
          {
          if (counter==0)
          ...
          else
          ...
          }

          Veni, vidi, abiit domum

          A 1 Reply Last reply
          0
          • L Lost User

            Firstly please format your code properly by using <pre> tags around it (see the "code" button above the edit box). That makes it so much easier to read as I have done below. Secondly, your design is really not the best way to do it. It is much better to use proper parameters to your functions and control those parameters from the caller, like:

            main()
            {
            counter=0;
            CallFun1(counter);
            counter=1;
            CallFun2(counter);
            CallFun3(counter);
            }

            // submodule.cpp
            CallFun2(int counter)
            {
            if (counter==0)
            ...
            else
            ...
            }

            CallFun3(int counter)
            {
            if (counter==0)
            ...
            else
            ...
            }

            Veni, vidi, abiit domum

            A Offline
            A Offline
            anne_rose
            wrote on last edited by
            #5

            Sorry Richard, i know it was bad programming.... Thanks once again ....

            L 1 Reply Last reply
            0
            • A anne_rose

              Sorry Richard, i know it was bad programming.... Thanks once again ....

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              anne_rose wrote:

              i know it was bad programming

              No problem, we all had to learn ...

              Veni, vidi, abiit domum

              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