[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] C++ : Konvertere fra WORD / DWORD til char (eller noget)



> Hejsa:
>
>
> jeg har stirret mig blind på det...
> Lad mig først lige starte med en tilståelse. Jeg er ved at lave et program
> til Windows (ja, jeg ved det...). I C++. Jeg kender ikke andre grupper end
> denne (bruger også linux sometimes :o), så jeg skriver her :
>
> Problemet:
>
> Jeg har en variabel "data" :
>         unsigned char data[1024];
> 
> Jeg har også en række andre variable :
>         unsigned long X1 = 0x0123;
>         unsigned long X2 = 0x1876;
>         unsigned long X3 = 0x9987;
>         doubble unsigned long X4 = 0x12348765;
>
> X1 til X4 skal lægges ind i rækkefølge i "data". Altså således at man kan
> pille dem ud af "data" igen uden at de ændres.
>
> Er der en smart måde at gøre det på eller hvordan? Jeg er selv helt tom for
> idéer, så ethvert forslag er velkomment!
>
> Thomas Rokamp

Hej Thomas.

Lidt afhængigt af problemet ville jeg bruge en pointer eller en union.

Union:
vel lidt a la:

union {
  char data[1024];
  struct {
    unsigned long X1;
    ...
  } named;
} dims;

Pointer:
Lav en pointer til unsigned long. Gem addressen på den plads i arrayet du vil
gemme i din pointer, og læg dit data der hvor pointeren peger.

unsigned long * en_ting;
en_ting=data+offset;   /* hvor offset indeholder index i arrayet */
(en_ting*)=X1;


Koden er altså med forbehold for at jeg har siddet på arbejde i 7 timer nu, og
ikke har testet den :)

MVH.
Michael Westergaard

____________________________________________________________________
Get free email and a permanent address at http://www.amexmail.com/?A=1


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *