Snippet #123092

TTL: forever — WordwrapView raw

on 2022/11/01 1:07:09 (UTC) by rotense as C

  1. #include "main.h"
  2. #include <stdio.h>
  3.  
  4. /**
  5.  * simple_print_buffer - prints buffer in hexa
  6.  * @buffer: the address of memory to print
  7.  * @size: the size of the memory to print
  8.  *
  9.  * Return: Nothing.
  10.  */
  11. void simple_print_buffer(char *buffer, unsigned int size)
  12. {
  13.         unsigned int i;
  14.  
  15.         i = 0;
  16.         while (i < size)
  17.         {
  18.                 if (i % 10)
  19.                 {
  20.                         printf(" ");
  21.                 }
  22.                 if (!(i % 10) && i)
  23.                 {
  24.                         printf("\n");
  25.                 }
  26.                 printf("0x%02x", buffer[i]);
  27.                 i++;
  28.         }
  29.         printf("\n");
  30. }
  31.  
  32. /**
  33.  * main - check the code
  34.  *
  35.  * Return: Always 0.
  36.  */
  37. int main(void)
  38. {
  39.     char buffer[98] = {0x00};
  40.  
  41.     simple_print_buffer(buffer, 98);
  42.     _memset(buffer, 0x01, 95);
  43.     printf("-------------------------------------------------\n");
  44.     simple_print_buffer(buffer, 98);    
  45.     return (0);
  46. }

Recent Snippets