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. storing value in buf

storing value in buf

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 5 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
    ikbahrian
    wrote on last edited by
    #1

    could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in.:doh: missing some values... len=0; unsigned char *buf; buf=(unsigned char *)malloc(12); *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04 len+=4; for(k=0,k

    C R G S 4 Replies Last reply
    0
    • I ikbahrian

      could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in.:doh: missing some values... len=0; unsigned char *buf; buf=(unsigned char *)malloc(12); *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04 len+=4; for(k=0,k

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      ikbahrian wrote:

      *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04

      shouldn't that be: *buf=0x01 *(buf+1)=0x02 *(buf+2)=0x03 *(buf+3)=0x04 ?

      image processing toolkits | batch image processing | blogging

      1 Reply Last reply
      0
      • I ikbahrian

        could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in.:doh: missing some values... len=0; unsigned char *buf; buf=(unsigned char *)malloc(12); *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04 len+=4; for(k=0,k

        R Offline
        R Offline
        Reagan Conservative
        wrote on last edited by
        #3

        ikbahrian wrote:

        *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04

        Should be: *buf=0x01 *(buf+1)=0x02 *(buf+2)=0x03 *(buf+3)=0x04

        John P.

        I 1 Reply Last reply
        0
        • R Reagan Conservative

          ikbahrian wrote:

          *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04

          Should be: *buf=0x01 *(buf+1)=0x02 *(buf+2)=0x03 *(buf+3)=0x04

          John P.

          I Offline
          I Offline
          ikbahrian
          wrote on last edited by
          #4

          thx john P.

          1 Reply Last reply
          0
          • I ikbahrian

            could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in.:doh: missing some values... len=0; unsigned char *buf; buf=(unsigned char *)malloc(12); *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04 len+=4; for(k=0,k

            G Offline
            G Offline
            Gary R Wheeler
            wrote on last edited by
            #5

            One final note: you should use

            printf("0x%.2x",**(unsigned)**buf[k]);

            since the %x format-specifier expects an int-sized value in the argument list.


            Software Zen: delete this;

            Fold With Us![^]

            1 Reply Last reply
            0
            • I ikbahrian

              could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in.:doh: missing some values... len=0; unsigned char *buf; buf=(unsigned char *)malloc(12); *buf=0x01 *(buf+1)=0x02 *(buf+1)=0x03 *(buf+1)=0x04 len+=4; for(k=0,k

              S Offline
              S Offline
              Sumesh V V
              wrote on last edited by
              #6

              unsigned char *buf = NULL; buf = (unsigned char *) malloc( 12 ); if( buf ) { *buf=0x01; *(buf+1)=0x02; *(buf+2)=0x03; *(buf+3)=0x04; *(buf+4)=NULL; for(int k=0 ; buf[k] != NULL; k++) { printf("0x%.2x ",buf[k]); } free( buf ); } I think this will work for u.:)

              I 1 Reply Last reply
              0
              • S Sumesh V V

                unsigned char *buf = NULL; buf = (unsigned char *) malloc( 12 ); if( buf ) { *buf=0x01; *(buf+1)=0x02; *(buf+2)=0x03; *(buf+3)=0x04; *(buf+4)=NULL; for(int k=0 ; buf[k] != NULL; k++) { printf("0x%.2x ",buf[k]); } free( buf ); } I think this will work for u.:)

                I Offline
                I Offline
                ikbahrian
                wrote on last edited by
                #7

                thx appoos

                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