Created
March 10, 2020 11:34
-
-
Save ololobus/a1276d61ac1b42f891477d966cedfe00 to your computer and use it in GitHub Desktop.
C fixed-size char buffer argument
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 <stdlib.h> | |
#define MAXBUFSIZE 20 | |
void put(char (*dest)[MAXBUFSIZE], char *src) | |
{ | |
strcpy((char *) dest, src); | |
} | |
int main() | |
{ | |
char buf1[MAXBUFSIZE]; | |
char *buf2 = malloc(MAXBUFSIZE);; | |
put(&buf1, "some text 1"); | |
put(buf2, "some text 2"); // XXX: how to cast and pass buf2 | |
// without warnings? | |
printf("%s\n", buf1); | |
printf("%s\n", buf2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment