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. C / C++ / MFC
  4. How to get value

How to get value

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorial
5 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I like to verify actuall value passed from char array to struct pointer buf array declaration unsigned char buf[32]; // = { 0x00, 0x04 }; value passed unsigned char 0x04; buf[0] = command; // passed 0x04 software reset transmit buffer assignment xfer[0].tx_buf = (unsigned long) buf; Now I like to use cout to print the actual value in tx_buf. From struct declaration I know "tx_buf" is a unsigned long pointer. Not sure how to access the required value this gives me the pointer as expected:

    cout << "xfer[0].tx_buf " << xfer[0].tx_buf<< endl;

    Once I know how to get first value I can probably figure out how to get the whole buf[32] array values.

    Thanks for help
    Cheers Vaclav

    L 1 Reply Last reply
    0
    • V Vaclav_

      I like to verify actuall value passed from char array to struct pointer buf array declaration unsigned char buf[32]; // = { 0x00, 0x04 }; value passed unsigned char 0x04; buf[0] = command; // passed 0x04 software reset transmit buffer assignment xfer[0].tx_buf = (unsigned long) buf; Now I like to use cout to print the actual value in tx_buf. From struct declaration I know "tx_buf" is a unsigned long pointer. Not sure how to access the required value this gives me the pointer as expected:

      cout << "xfer[0].tx_buf " << xfer[0].tx_buf<< endl;

      Once I know how to get first value I can probably figure out how to get the whole buf[32] array values.

      Thanks for help
      Cheers Vaclav

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

      You need to print each byte independently, after casting them to int, since the char values are unprintable. Something like:

      cout << hex << (int)buf[0] << endl;

      Use a loop to print more than one value.

      V 1 Reply Last reply
      0
      • L Lost User

        You need to print each byte independently, after casting them to int, since the char values are unprintable. Something like:

        cout << hex << (int)buf[0] << endl;

        Use a loop to print more than one value.

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        Thanks, but... I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct. I am having issues verifying that the struct has all of the necessary data. Some are "straight" values, most via pointers. BTW When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;, then following usage WITHOUT such modifier will continue to print the data in hex cout << int)buf[0] << endl; Nice but it can get out of control.

        L 1 Reply Last reply
        0
        • V Vaclav_

          Thanks, but... I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct. I am having issues verifying that the struct has all of the necessary data. Some are "straight" values, most via pointers. BTW When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;, then following usage WITHOUT such modifier will continue to print the data in hex cout << int)buf[0] << endl; Nice but it can get out of control.

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

          Vaclav_ wrote:

          I am having issues verifying that the struct has all of the necessary data.

          You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork. See <iomanip> functions[^] for details on using the hex manipulator.

          V 1 Reply Last reply
          0
          • L Lost User

            Vaclav_ wrote:

            I am having issues verifying that the struct has all of the necessary data.

            You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork. See <iomanip> functions[^] for details on using the hex manipulator.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            I just like to see the value passed to struct pointer. I can deal with what the functio0n does with it myself. Perhaps it is all working correctly and my problems are elsewhere.

            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