c_cpp 允许在C中模式化字节

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 允许在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;
}

以上是关于c_cpp 允许在C中模式化字节的主要内容,如果未能解决你的问题,请参考以下文章