Last active
January 8, 2020 08:05
-
-
Save frankie-yanfeng/06f2d8042909431e8b07a70516a1b60e to your computer and use it in GitHub Desktop.
Two Layer Pointers
This file contains hidden or 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
/* main.c */ | |
#include <stdio.h> | |
#include "redirect_ptr.h" | |
int main(void) | |
{ | |
const char *firstday = NULL; | |
const char *secondday = NULL; | |
get_a_day(&firstday); | |
get_a_day(&secondday); | |
printf("%s\t%s\n", firstday, secondday); | |
return 0; | |
} |
This file contains hidden or 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
/* redirect_ptr.c */ | |
#include "redirect_ptr.h" | |
static const char *msg[] = {"Sunday", "Monday", | |
"Tuesday", "Wednesday", | |
"Thursday", "Friday", | |
"Saturday"}; | |
void get_a_day(const char **pp) | |
{ | |
static int i = 0; | |
*pp = msg[i%7]; | |
i++; | |
} |
This file contains hidden or 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
#ifndef TWOLAYERPOINTERS_REDIRECT_PTR_H | |
#define TWOLAYERPOINTERS_REDIRECT_PTR_H | |
extern void get_a_day(const char **); | |
#endif //TWOLAYERPOINTERS_REDIRECT_PTR_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment