Archived

This topic is now archived and is closed to further replies.

Can i do this with memcpy?

This topic is 5316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
I''m beginning to see why the Unix elite took to their mantra of RTFM

Share this post


Link to post
Share on other sites
Sure, you can do it. It won''t do what you''re probably wanting, though. It''s copying the first 256 bytes of a FILE structure (not the file itself!) into buff. A FILE struct is only 32 bytes (in Visual C++ 6.0 on Windows, anyway), so the rest of your 256 bytes will just be garbage.

If you want the first 256 bytes of a file, try:


  
FILE *fp;
char buf[256];

fp = fopen("file", "rb");
if(fp)
{
fread(buff, 256, 1, fp);
}

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
I''m beginning to see why the Unix elite took to their mantra of RTFM


If you are suggesting i should''ve read the manual for memcpy then i should tell you that i read the manpages for memcpy, but it says nothing about not working with reading files. A file could be easily copied to memory. Dumbass.

Thanks for the reply, BriTeg. I know i can do fread, but i was just wondering if it could be done with memcpy.

Victor.

Share this post


Link to post
Share on other sites
If you want to read/write files like memory in unix look at the man pages for mmap. Under windows look at CreateFileMapping.

[edited by - MauMan on May 27, 2003 4:42:31 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by MauMan
If you want to read/write files like memory in unix look at the man pages for mmap. Under windows look at CreateFileMapping.

[edited by - MauMan on May 27, 2003 4:42:31 PM]


Thanks!
Victor.

Share this post


Link to post
Share on other sites