| | |
Help with folding a character array please
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
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.
Could someone please tell me how to fold the character array in this manner?
Thanks.
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
May be this code sample will be of some help.Just have a look at it.
Code tags added. -Narue
bye
ssv
C Syntax (Toggle Plain Text)
/***** required macros and structures *****************/ union example { char array[6]; struct ints { short a; short b; short c; }x; }; union example e1; #define swapbytes(z) (((short)(z << 8)) | ((short)(z >> 8))) /********************example code snippet ****************/ int main(int argc, char* argv[]) { memcpy(e1.array,"aBCDEF",6); printf ("value of array = %s\n",e1.array); printf("value of a = %X\n",swapbytes(e1.x.a)); printf("value of b = %X\n",swapbytes(e1.x.b)); printf("value of c = %X\n",swapbytes(e1.x.c)); printf("value of a + b + c = %X\n",swapbytes(e1.x.a) + swapbytes(e1.x.b) + swapbytes(e1.x.c)); printf("Hello World!\n"); return 0; }
bye
ssv
![]() |
Similar Threads
- Sorting a string or character array (C++)
- Character Array to character pointer. (C)
- 2-D array (C++)
- Problem with string search of an array (C++)
- how to increase the size of an array? (C)
- Sorting character arrays! (C++)
- How do I create a program using an Array ? (C++)
- character processing (C)
Other Threads in the C Forum
- Previous Thread: Very Hard Assignment, Queues
- Next Thread: File Processing
Views: 3080 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi





