memcpy

This is a discussion on memcpy within the C Programming forums, part of the General Programming Boards category; i am trying to use memcpy but it gives me a compile error this is what i am doing Code: ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    31

    Unhappy memcpy

    i am trying to use memcpy but it gives me a compile error

    this is what i am doing

    Code:
    char *temp;
    char space[21];
    
    temp = malloc(5000);
    strncpy(space, "                    ", 21);
    memcpy(temp, space, 21);

    what is wrong?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by mbooka
    i am trying to use memcpy but it gives me a compile error
    What error might that be?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    31
    the errors is on the memcpy line

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Again, what might that error be.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    31
    my error that i get or the error i think is wrong with the code?

    if it is the first one all i get is

    "pass error"

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    31
    after looking at my code for a couple of minutes i realise that it was my stupid fault and left out a small but significant ';'.

    ...

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    This is why we copy the code into our post and not rewrite it.
    Sent from my iPadŽ

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by mbooka
    this is what i am doing
    You may want to consider doing something like this.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main()
    {
       size_t size = 21;
       char *temp = malloc(size);
       if ( temp != NULL )
       {
          memset(temp, ' ', size - 1);
          temp[size - 1] = '\0';
          printf("temp = \"%s\"\n", temp);
          free(temp);
       }
       return 0;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    31
    I will keep that in mind when memcpy doesnt seem to work.

    Also with regards to SlyMaelstrom comment, i cant copy my code because i cant copy from cygwin. I work remotely on a unix machine on a windows platform.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pipe your output to a text file. Open it, copy-paste. Or of course you could simply open up a text editor, type the error out as you see it... or the post box... Yeah, it's not real hard to figure out a way to tell us the actual error if you're not too freeking lazy to do it.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > i cant copy my code because i cant copy from cygwin
    This is a load of BS - I do this all the time.
    All you have to do is click on the properties icon in the title bar and enable editing (just like you would if it were a win32 console window).

    Now post accurate information from now on, not heresay ramblings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disagreement about memcpy
    By ch4 in forum C Programming
    Replies: 9
    Last Post: 05-28-2009, 10:12 AM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Memcpy(); Errors...
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2006, 10:35 AM
  4. memcpy with 128 bit registers
    By grady in forum Linux Programming
    Replies: 2
    Last Post: 01-19-2004, 05:25 AM
  5. memcpy
    By doubleanti in forum C++ Programming
    Replies: 10
    Last Post: 02-28-2002, 03:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21