0

Hi,
This is a segmant of my code that iam working on, for some reason its not giving out the expected output :( which is 11010111. It gives me "elements: ☺ ☺ ☺ ☺ ☺ ☺" and its really bugging me cuz it looks right. Any help would be appriciated. Thanks

unsigned char ipans[8],ipb[4]={1,0,1,1},epans[8];
int           ep[8] = {4,1,2,3,2,3,4,1};


int main()
{
    int x;
      
      printf("elements: ");
      for(x=0;x<8;x++)
      {
         epans[x] = ipb[ep[x]-1];
         printf("%c " ,epans[x]);
      }
3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by TkTkorrovi
0

Yes, Salem is right, %c gives you a character with a corresponding code, not a number, 1 1 0 1 0 1 1 1 is exactly what your program outputs when you use %d. Also, when you initialize the arrays, you don't always have to provide the size, like in your program ipb [] = {1, 0, 1, 1} would work as well. One more thing, when you use the initialized arrays, it's often better to not use the array size anywhere, to avoid an unnecessary magic number. Like, in your array ep, the elements most likely cannot be 0, so, you can end this array with zero, and iterate until zero.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.