Groups | Search | Server Info | Login | Register


Groups > comp.lang.c.moderated > #410

Re: distributing data across a structure (new to c please help)

From Dennis Yurichev <dennis_mailing_lists@conus.info>
Newsgroups comp.lang.c.moderated
Subject Re: distributing data across a structure (new to c please help)
Date 2012-08-20 14:17 -0500
Organization Aioe.org NNTP Server
Message-ID <clcm-20120820-0001@plethora.net> (permalink)
References <clcm-20120809-0001@plethora.net>

Show all headers | View raw


nwdpil <mkeput@gmail.com> writes:

> the ulimate goal is to read the MZ header from a binary windows pe
> file, which is simple enough. anyway the theory goes (and this is the
> bit i dont understand im new to c programming) i memcpy the data from
> the file ACROSS a struct. is this possible? i dont understand how to
> initialise and manipulate the struct. can i copy a set of data that is
> 16bytes long, to a struct with two 8byte children and will memcpy then
> distribute the data for me if i pass it pointers?
>
> it sounds easy but im really struggling to get to grips with
> it. anyway heres a simple c program i wrote to demonstrate the
> concept. it fails with the error Run-Time Check Failure #3 - The
> variable 'x' is being used without being initialized.
>
> for example i should be able to access string "00004444" with x->b; and "eeeeffff" with x->bb;
>
> im on windows running visual c++ 2010 express, although im coding
> purely in c because i never saw the point in object orientated
> programming.
>
> help please?
>
> [code]
> // pointblank.c : Defines the entry point for the console application.
> //
>
> #include "stdafx.h"
> #include "stdio.h"
> #include "stdlib.h"
> #include "string.h"
>
> typedef struct _test {
> 	char b[8];
> 	char bb[8];
> }; test, *ptest;

Also, do not forget about C compiler may align all struct members by 4
bytes on x86 and 8 bytes on Win64. 
Since Windows PE file fields are all differently sized and this is very
important, please consult "pack" pragma:
http://msdn.microsoft.com/en-us/library/2e70t5y1(v=vs.80).aspx
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

distributing data across a structure (new to c please help) nwdpil <mkeput@gmail.com> - 2012-08-09 20:32 -0500
  Re: distributing data across a structure (new to c please help) James Kuyper <jameskuyper@verizon.net> - 2012-08-10 00:43 -0500
  Re: distributing data across a structure (new to c please help) Dennis Yurichev <dennis_mailing_lists@conus.info> - 2012-08-20 14:17 -0500
    Re: distributing data across a structure (new to c please help) Keith Thompson <kst-u@mib.org> - 2012-08-20 22:10 -0500
    Re: distributing data across a structure (new to c please help) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-20 22:11 -0500

csiph-web