Skip to content

Instantly share code, notes, and snippets.

@ololobus
Created March 10, 2020 11:34
Show Gist options
  • Save ololobus/a1276d61ac1b42f891477d966cedfe00 to your computer and use it in GitHub Desktop.
Save ololobus/a1276d61ac1b42f891477d966cedfe00 to your computer and use it in GitHub Desktop.
C fixed-size char buffer argument
#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