Skip to content

Instantly share code, notes, and snippets.

@wirewc
Last active August 29, 2015 14:12
Show Gist options
  • Save wirewc/d2bc86322812bf37e66c to your computer and use it in GitHub Desktop.
Save wirewc/d2bc86322812bf37e66c to your computer and use it in GitHub Desktop.
Example code to popular a char pointer in a function through a function argument pointer. This example is for anyone who has beat their against the wall. This example is used as a mock up for how one may try pull a buffer from a microcontroller that is built for a UART interrupt.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void copy_string(char *target, char *source)
{
while(*source)
{
*target = *source;
source++; target++;
}
*target = '\0';
}
void implant(char *stuff)
{
char loader[] = "Hello";
copy_string(stuff, (char*)loader);
}
int main(void)
{
char *toload = malloc(20);
implant(toload);
printf("%s\n",toload);
free(toload);
implant(toload);
printf("%s\n",toload);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment