Type Here to Get Search Results !

Memory operations in C Programming

Restricted vs. Unrestricted String Functions 

Restricted versions: Require an extra integer argument that bounds the operation. 
char *strncpy (char *dst, char const *src, size); 
char *strncat (char *dst, char const *src, size); 
int strncmp (char const *sl, char const *s2, size); 
    To avoid problems with missing NULL terminators 'strncpy' is used: 
    The safe alternative is given as: 
    strncpy (buffer, name, BSIZE); 
    buffer[BSIZE-1] = '\0'; 
Unrestricted versions: A function is said to be unrestricted if the size is not mentioned.

Memory operations 
Like string operations, memory operations work on sequences of bytes but do not terminate when NULL is encountered. 
void *memcpy(void *dst, void const *src, size_t length); 
void *memcmp(void const *a, void const *b, size_t length); 
Note: 
 'memmove' works like 'memcpy', but allows overlapping source, destination regions. 
Remember, these operations work on bytes 
    If you want to copy N items of type T, get the length right: 
    memcpy (to, from, N * sizeof(T))

Top Post Ad

Below Post Ad