How to extract a part of a char array in C? -


i receive 10 bytes (010830ffffffffff0304) in hexa on terminal, , need write part of array (this 5 bytes ffffffffff) in char array.

here“s code:

#include <stdio.h>  void main(){     char buffer[];  // buffer size in bytes     int i;          // counter     while(true){         for(i=0; i<buffer; i++){             buffer[i] = getc();         }     } } 

how extract part of array?

general fixup:

  • i declared actual size buffer (10), did not have size.
  • i declared array answer (middle), did not have such space.
  • i loop 10 times, instead of non-sense comparison i<buffer
  • i removed outer while(true), never terminate.
  • i memcpy input buffer answer, 5 characters.

your question unclear , imprecise, can guess @ intended.

void main() {     char buffer[10]; // buffer size in bytes     char middle[5];     int i; // counter      for(i=0; i<10; ++i){         buffer[i] = getc();     }      memcpy(middle, &buffer[3], 5*sizeof(char));      for(i=0; i<5; ++i)     {         printf("%x",middle[i]);     }     printf("\n"); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -