1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help in understanding a loop

Discussion in 'C' started by lionaneesh, May 31, 2010.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Code:
    // Dumps raw memory in hex byte and printable split format
    void dump(const unsigned char *data_buffer, const unsigned int length) {
       unsigned char byte;
       unsigned int i, j;
       for(i=0; i < length; i++) {
          byte = data_buffer[i];
          printf("%02x ", data_buffer[i]);  // Display byte in hex.
          if(((i%16)==15) || (i==length-1)) {
             for(j=0; j < 15-(i%16); j++)
                printf("   ");
             printf("| ");
             for(j=(i-(i%16)); j <= i; j++) {  // Display printable bytes from line.
                byte = data_buffer[j];
                if((byte > 31) && (byte < 127)) // Outside printable char range
                   printf("%c", byte);
                else
                   printf(".");
             }
             printf("\n"); // End of the dump line (each line is 16 bytes)
          } // End if
       } // End for
    }
    Hey guys i Found this code on the Net somewhere.
    What it does it is written on the top of it .

    I am facing problems understanding this function :-

    Code:
    if(((i%16)==15) || (i==length-1)) {
             for(j=0; j < 15-(i%16); j++)
                printf("   ");
             printf("| ");
             for(j=(i-(i%16)); j <= i; j++) {  // Display printable bytes from line.
                byte = data_buffer[j];
                if((byte > 31) && (byte < 127)) // Outside printable char range
                   printf("%c", byte);
                else
                   printf(".");
    I am not getting what is exactly happening in this loop!!!

    Need you help guys please explain me this..
     

Share This Page