Created
April 7, 2014 14:58
-
-
Save andreabadesso/10021959 to your computer and use it in GitHub Desktop.
Trying to access struct members knowing the data format
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
int codifica(void* valores, char *campos) { | |
char tipo; | |
int acc = 0; | |
int acc2 = 0; | |
int i; | |
for (i=0;i<=strlen(campos);i++) { | |
tipo = campos[i]; | |
// p = *(int*)valores; | |
// v = (*((int*)valores+1)); | |
// c = (*((char*)valores + sizeof(char*))); | |
//printf("%d, %d, %c\n", p,v,c); | |
switch(tipo) { | |
case 'i': | |
int i_valor; | |
i_valor = (*((int*)valores+acc)); | |
printf("endereco: %p\n", ((((int*)valores+acc)))); | |
printf("valor: %d\n", i_valor); | |
acc += 1; | |
acc2 += 4; | |
break; | |
case 's': | |
char* c_valor; | |
printf("endereco: %p\n", ((((char*)valores+acc)))); | |
c_valor = &(*((char*)valores+acc2)); | |
printf("valor: %s\n", c_valor); | |
acc += sizeof(c_valor); | |
// Fazer alguma coisa | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment