Created
August 18, 2013 00:07
-
-
Save leite/6259269 to your computer and use it in GitHub Desktop.
wtf, multidimensional array o chars
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
#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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hehe ... não quis ofender, só achei conveniente deixar na mão já, me ajuda padre :P