jweinst1
11/14/2017 - 7:26 PM

Allows patterning of bytes in C

Allows patterning of bytes in C

#include <stdio.h>
#include <stdlib.h>

//writes increments of data pre-marked by a type marker.
void ByteWrite_mark(void* restrict dest, void* restrict src, size_t block, unsigned char mark, int amount)
{
  unsigned char* reader = src;
  unsigned char* writer = dest;
  size_t currBlock;
  while(amount--)
  {
    //marks data
    *writer++ = mark;
    currBlock = block;
    while(currBlock--)
    {
      *writer++ = *reader++;
    }
  }
}
/*
1
1
0
0
0
1
55
0
0
0
1
78
0
0
0*/





int main(void) {
  unsigned char start[] = {1, 0, 0, 0, 55, 0, 0, 0, 78, 0, 0, 0};
  unsigned char end[50];
  ByteWrite_mark(end, start, 4, 1, 3);
  for(size_t i =0;i<15;i++) printf("%u\n", end[i]);
  return 0;
}