I'm trying to fill the array "g" with letters from the array "letras" given a certain condition. Everything is working fine, except I couldn't do it... Strange characters appear when I run the code. What am i doing wrong?
Note: This is a part of a function. "vetor" is a parameter that was passed to this function.
Code:
int i;
int j = 0;
char g[20];
char letras[5] = {'a', 'b', 'c', 'd', 'n'};
while(j < g)
{
for(i = 0; i < 80; i = i + 4)
{
if(vetor[i] == 1 && vetor[i + 1] == 0 && vetor[i + 2] == 0 && vetor[i + 3] == 0)
{
letras[0] = g[j];
printf("%c\n", g[j]);
j++;
}
else if(vetor[i] == 0 && vetor[i + 1] == 1 && vetor[i + 2] == 0 && vetor[i + 3] == 0)
{
letras[1] = g[j];
printf("%c\n", g[j]);
j++;
}
else if(vetor[i] == 0 && vetor[i + 1] == 0 && vetor[i + 2] == 1 && vetor[i + 3] == 0)
{
letras[2] = g[j];
printf("%c\n", g[j]);
j++;
}
else if(vetor[i] == 0 && vetor[i + 1] == 0 && vetor[i + 2] == 0 && vetor[i + 3] == 1)
{
letras[3] = g[j];
printf("%c\n", g[j]);
j++;
}
else
{
letras[4] = g[j];
printf("%c\n", g[j]);
j++;
}
}
}