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. (u_char *)

(u_char *)

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 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.
  • I Offline
    I Offline
    idineen
    wrote on last edited by
    #1

    hi there, i need to send the decimal number "2" as a parameter to a function, but the method passes this parameter as a (u_char *). how can i stop this number from being converted to its ascii value of 50 when passing it through the parameter. i can't send the ascii value of "2", as this is defined as STX in ascii table. ian dineen

    T 1 Reply Last reply
    0
    • I idineen

      hi there, i need to send the decimal number "2" as a parameter to a function, but the method passes this parameter as a (u_char *). how can i stop this number from being converted to its ascii value of 50 when passing it through the parameter. i can't send the ascii value of "2", as this is defined as STX in ascii table. ian dineen

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      "2" is not a number but a C-Style null terminated string (actually, an array of two chars : { '2', '\0' }.

      idineen wrote:

      how can i stop this number from being converted to its ascii value of 50 when passing it through the parameter.

      can you show us a piece of the code by which you call the function, and how the function uses this parameter too ?? i'm quite sure you don't use it properly.

      I 1 Reply Last reply
      0
      • T toxcct

        "2" is not a number but a C-Style null terminated string (actually, an array of two chars : { '2', '\0' }.

        idineen wrote:

        how can i stop this number from being converted to its ascii value of 50 when passing it through the parameter.

        can you show us a piece of the code by which you call the function, and how the function uses this parameter too ?? i'm quite sure you don't use it properly.

        I Offline
        I Offline
        idineen
        wrote on last edited by
        #3

        the code below is used to put a snmp object id into a pdu packet along with 3 parameters. the third parameter is used by the program to identify that the paramter is interrupted as a integer. the 4th parameter "test" is the number that i want to pass, this parameter is of type "(u_char *)" and the last is the length of the string. snmp_pdu_add_variable(pdu, oid, oid_length, ASN_INTEGER , test, strlen(test));// thanks ian

        K R 2 Replies Last reply
        0
        • I idineen

          the code below is used to put a snmp object id into a pdu packet along with 3 parameters. the third parameter is used by the program to identify that the paramter is interrupted as a integer. the 4th parameter "test" is the number that i want to pass, this parameter is of type "(u_char *)" and the last is the length of the string. snmp_pdu_add_variable(pdu, oid, oid_length, ASN_INTEGER , test, strlen(test));// thanks ian

          K Offline
          K Offline
          koothkeeper
          wrote on last edited by
          #4

          Hi Idineen: Do you have access to the source code of snmp_pdu_add_variable? It could be that all variables are passed in as u_char*, then because of ASN_INTEGER, that function has code to convert it to an integer from the string value in test.

          1 Reply Last reply
          0
          • I idineen

            the code below is used to put a snmp object id into a pdu packet along with 3 parameters. the third parameter is used by the program to identify that the paramter is interrupted as a integer. the 4th parameter "test" is the number that i want to pass, this parameter is of type "(u_char *)" and the last is the length of the string. snmp_pdu_add_variable(pdu, oid, oid_length, ASN_INTEGER , test, strlen(test));// thanks ian

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            Try this:

            int test = 2;
            snmp_pdu_add_variable(pdu, oid, oid_length, ASN_INTEGER, reinterpret_cast<u_char*>(&test), sizeof(test));

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            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