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: ");
         epans[x] = ipb[ep[x]-1];
         printf("%c " ,epans[x]);
Re: array, unexpected output 80 80

Use %d
Not %c

Re: array, unexpected output 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.