storing value in buf
-
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
-
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
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
-
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
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.
-
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.
-
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
One final note: you should use
printf("0x%.2x",**(unsigned)**buf[k]);
since the
%x
format-specifier expects anint
-sized value in the argument list.
Software Zen:
delete this;
-
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
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.:)
-
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.:)