Skip to content

Instantly share code, notes, and snippets.

@andreabadesso
Created April 8, 2014 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreabadesso/10078067 to your computer and use it in GitHub Desktop.
Save andreabadesso/10078067 to your computer and use it in GitHub Desktop.
rodolfobixa
int codifica(void* valores, char *campos) {
char tipo;
int acc = 0;
int i;
int temint = 0;
int ultimoChar = 0;
int padding = 0;
int pad = 0;
for (i=0;i<=strlen(campos);i++) {
tipo = campos[i];
switch(tipo) {
case 'i':
char i_valor;
temint = 1;
// if (ultimoChar == 1) {
// acc += pad;
// }
i_valor = (*((char*)valores+acc));
printf("valor: %d\n", i_valor);
acc += 4;
ultimoChar = 0;
break;
case 's':
char* c_valor;
int x = 0;
if (ultimoChar == 1) {
acc = acc - padding;
}
c_valor = &(*((char*)valores+acc));
while(c_valor[x] != '\0') {
printf("%c", c_valor[x]);
x++;
}
x++;
printf("\n");
acc += x;
padding = x % 4;
// if (ultimoChar == 1) {
// pad = padding;
// padding = 0;
// }
if (padding > 0 && temint > 0) {
padding = 4 - padding;
acc += padding;
}
ultimoChar = 1;
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment