[Solved] Weird results in c [closed]


In addition to LihOs answer above this block looks wrong:

if(tab1[i] != '\0') 
  tab1[i]==result[i];
else if (tab2[i] !='\0')
  tab2[i]==result[i];
else printf(" ");

Don’t you mean to assign the value in tab1[i]or tab2[i] to result[i]like this?

if(tab1[i] != '\0') 
  result[i] = tab1[i];
else if (tab2[i] !='\0') 
  result[i] = tab2[i];
else printf(" ");

Also using magic numbers like in the loops: for(i=0;i<30;i++) is pretty bad practice, you should probably be using a constant for the size value (which you could then use in both the loops and in the array declarations. And why loop to 30 when the arrays is 10 elements only?

1

solved Weird results in c [closed]