Help with folding a character array please

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2005
Posts: 1
Reputation: nailzfan is an unknown quantity at this point 
Solved Threads: 0
nailzfan nailzfan is offline Offline
Newbie Poster

Help with folding a character array please

 
0
  #1
Apr 5th, 2005
hello all, this is my first time posting. Okay, I'm reading a character array from a .dat file. The character array has 6 elements and I'm supposed to fold the integer values of the character array. The professor wants us to pair up consecutive indexes and add them together. For ex: "ABCDEF" would be 6566 + 6768 + 6970. This is part of an assignment to create a hash table.
Could someone please tell me how to fold the character array in this manner?
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1
Reputation: ssv is an unknown quantity at this point 
Solved Threads: 0
ssv ssv is offline Offline
Newbie Poster

Re: Help with folding a character array please

 
0
  #2
Apr 5th, 2005
May be this code sample will be of some help.Just have a look at it.
  1. /***** required macros and structures *****************/
  2. union example
  3. {
  4. char array[6];
  5. struct ints
  6. {
  7. short a;
  8. short b;
  9. short c;
  10. }x;
  11. };
  12.  
  13. union example e1;
  14. #define swapbytes(z) (((short)(z << 8)) | ((short)(z >> 8)))
  15.  
  16.  
  17. /********************example code snippet ****************/
  18. int main(int argc, char* argv[])
  19. {
  20.  
  21. memcpy(e1.array,"aBCDEF",6);
  22. printf ("value of array = %s\n",e1.array);
  23. printf("value of a = %X\n",swapbytes(e1.x.a));
  24. printf("value of b = %X\n",swapbytes(e1.x.b));
  25. printf("value of c = %X\n",swapbytes(e1.x.c));
  26. printf("value of a + b + c = %X\n",swapbytes(e1.x.a) + swapbytes(e1.x.b) + swapbytes(e1.x.c));
  27. printf("Hello World!\n");
  28. return 0;
  29. }
Code tags added. -Narue

bye
ssv
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3080 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC