I am trying to POINT to each byte in an array and pass that info along to the main, thus resulting in each byte being looped. I am getting the correct out put but the index where I need it, is not correct . I am new to C so please forgive me if I am missing something simple.
output should look like :
00 00 00 00 0 0
01 00 00 00 1 1 This would be @ index c_ptr[0]
at c_ptr[1] I would get
00 01 00 00 256 256
00 02 00 00 512 512
and so on , here is what I coded :
Code:
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
void print_hex_signed_unsigned(int i)
{
unsigned char* c_ptr = (char*)&i;
printf( "The Value is: %02X 00 00 00 %14d %14u\n", c_ptr[0],i,i);
printf( "The Value is: 00 %02X 00 00 %14d %14u\n", c_ptr[1],i,i);
printf( "The Value is: 00 00 %02X 00 %14d %14u\n", c_ptr[2],i,i);
printf( "The Value is: 00 00 00 %02X %14d %14u\n", c_ptr[3],i,i);
}
int main ()
{
int i;
int index;
for (index = 0; index <256; index++)
print_hex_signed_unsigned(index * 1);
for (index = 0; index <256; index++)
print_hex_signed_unsigned(index * 256);
for (index = 0; index <256; index++)
print_hex_signed_unsigned(index * 65536);
for (index = 0; index <256; index++)
print_hex_signed_unsigned(index * 16777216);
getch();
return(0);
}
Thank you everyone for all the help !!