Created
August 9, 2012 09:55
-
-
Save andresv/3302804 to your computer and use it in GitHub Desktop.
memcpy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdint.h> //uint8_t and friends | |
int main(void){ | |
uint8_t settings[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; // preamble, stx and other stuff must be defined here | |
char text[] = "hello world"; | |
uint8_t message[100]; // this is the buffer where we put all the data that must be sent out | |
uint8_t i; | |
memcpy(message, settings, sizeof(settings)/sizeof(uint8_t)); // copy settings to the message buffer | |
memcpy(message+sizeof(settings)/sizeof(uint8_t), text, sizeof(text)); // append text to the message buffer (they must be after settings) | |
for (i=0; i<20; i++) { | |
printf("[%02d] %02X %c\n", i, message[i], message[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment