please reply for this queries

Discussion in 'C' started by prem_may10, Oct 9, 2006.

  1. prem_may10

    prem_may10 New Member

    Joined:
    Sep 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    hi
    1. what is the difference between strcpy and memcpy
    2. what is memory leak?
    3. what is the difference between general operating system and real time operating system.


    Thanks
    yasodhar premchand
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    strcpy

    strcpy allows null-terminated memory blocks to be copied to different locations. Since, in C, strings are not first-class datatypes, and are implemented as blocks of ASCII bytes in memory, strcpy will effectively copy strings given two pointers to blocks of allocated memory.

    memcpy

    memcpy() works on arbitrary data of a given fixed length

    use memcpy() when you want to copy an exact amount of data (possibly containing embedded null chars) from one location to another, and strcpy() when you want to copy a variable-length null-terminated C string from one location to another...

    Memory leaks are often thought of as failures to release unused memory by a computer program. Strictly speaking, it is just unneccesary memory consumption. As an example Making malloc calls without the corresponding calls to free.

    OS which performs the task in the real time environment. As an example say you need to embedded applications (programmable thermostats, household appliance controllers, mobile telephones), which cannot take more than a specified time to complete an operation but your normal OS can.
     
  3. prem_may10

    prem_may10 New Member

    Joined:
    Sep 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    hi
    still i am not getting the diffrence between strcpy and memcpy. can u explain with examples.


    Thanks
    yasodhar premchand
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    strcpy is used for copying strings (terminated by a null '\0') but memcpy can be used to copy some data of finite length to the desired memory location.

    memcpy(bufDest,bufSrc,100); // Will copy 100 bytes whatever be the content be

    strcpy(bufDest,bufSrc); // Will copy all the bytes till it finds the first null terminating character
     
  5. gunshot08

    gunshot08 New Member

    Joined:
    Jun 6, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice