samedi 25 juin 2016

Array to Pointer Syntax Error

I was trying to convert from array to pointer syntax, but I believe that I have made a mistake somewhere. Can anyone point out where?

/** Uses array-based logic to access a specified portion of a region of memory and print the corresponding bytes to a supplied file stream.

* Pre: Out is open on a file
* Base[0] is the first byte of the memory region to be examined
* Index is the index of the first relevant byte of the memory region
* nToPrint is the number of bytes to be printed
* Comments:
* This uses array syntax to access the bytes in the memory block.
*/

void showBytesAtIndex(FILE* Out, const uint8_t Base[], uint16_t Index, uint8_t nToPrint) {

 for (uint8_t pos = 0; pos < nToPrint; pos++) {

   fprintf(Out, " %02X", Base[Index + pos]);
}

  fprintf(Out, "n");
}

However, I have written this in pointer syntax (shown below) but it isn't working. Have I done something wrong?

/**  Uses pointer-based logic to access a specified portion of a region of memory and copy the corresponding bytes to a supplied array.
 * 
 *   Pre:   pDest points to an array of dimension nBytes + 1, or greater
 *          baseAddr points to the first byte of the memory region
 *          Offset is the location, relative to baseAddr, of the first
 *             relevant byte of the memory region
 *          nBytes is the number of bytes to be copied
 *   Restrictions:
 *      You must use only pointer syntax in accessing the data.
 */

    void getBytesAtOffset(uint8_t* const pDest, const uint8_t* const baseAddr, uint16_t Offset, uint8_t nBytes) {

   for (uint8_t pos = 0; pos < nBytes; pos++) {
       fprintf(*pDest, " %02X", (uint8_t) *(baseAddr + (Offset + pos))); 
   }
   fprintf(*pDest, "n");
}

Aucun commentaire:

Enregistrer un commentaire