Last active
August 29, 2015 14:12
-
-
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.
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 <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