Skip to content

Instantly share code, notes, and snippets.

@leite
Created August 18, 2013 00:07
Show Gist options
  • Save leite/6259269 to your computer and use it in GitHub Desktop.
Save leite/6259269 to your computer and use it in GitHub Desktop.
wtf, multidimensional array o chars
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#if !defined mempcpy
void *mempcpy(void *dst, const void *src, size_t len) {
return (char *) memcpy(dst, src, len) + len;
}
#endif
int main() {
int i;
char **a, *b[] = {"c", "de"};
a = (char **) malloc(2 * sizeof(char *));
for(i = 0; i < 2; ++i) {
a[i] = (char *) malloc(3 * sizeof(char));
*((char *) mempcpy ((char *)a[i], (i==0 ? "xy" : "kk"), 3)) = '\0';
}
// check positions
printf(" a[0] = %s\n", a[0]);
printf(" a[1] = %s\n", a[1]);
// check length
printf(" sizeof a[] -- %d\n", (int)(sizeof(a)/sizeof(a[0])));
printf(" sizeof b[] -- %d\n", (int)(sizeof(b)/sizeof(b[0])));
return 0;
};
@ademar111190
Copy link

kkk ensinando padre a reza :P

@leite
Copy link
Author

leite commented Aug 18, 2013

hehe ... não quis ofender, só achei conveniente deixar na mão já, me ajuda padre :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment