Sponsored Content
Full Discussion: memset vs calloc
Top Forums UNIX for Advanced & Expert Users memset vs calloc Post 302215338 by salvi on Wednesday 16th of July 2008 06:02:28 AM
Old 07-16-2008
memset vs calloc

Dear Friends,
Can any one tell me the difference between memset and calloc function in C.

Regards,
Selvi
 

8 More Discussions You Might Find Interesting

1. Programming

about memset fuction

Dear all, In my code,i am planning to use memset function to re-initialise an array before populating it everytime. Will using memset function be an overload to the program? (3 Replies)
Discussion started by: ranj@chn
3 Replies

2. UNIX for Dummies Questions & Answers

questions in memset

HI all , please find the piece of code below char *t; char *f; char buf; memset(buf,0,50); after that i am assigning memory for (i=0; i<100; i++) { t = buf+(i*6); f = "ARUN"; } my question .. 1) i have run this it is... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

3. Solaris

application Crashes on memset ?? any suggestions

Hi All, we have an application that is written in 'C' programming to connects to various servers in the organization. The bellow code establish a TCP connection to connect to the remote servers. the application works perfectly ok, but, after some time the entire process get's crashed and... (2 Replies)
Discussion started by: sudharma
2 Replies

4. Programming

C bzero() to memset() issue

Hi guys, my tool works fine in gentoo, ubuntu now im trying to port it to windows but bzero/bcopy I read aren't working on windows and for better portability I should of use memset() so im trying to translate bzero(buffer,256);in printf("MAIL TO"); strcpy(buffer, rcp); ... (4 Replies)
Discussion started by: Jess83
4 Replies

5. Programming

Calloc C++

Hello all, I have a confusion with calloc function : wz. the difference between the following 2 statemnts: char *ptr; char = (char*)calloc(num, sizeof(char)); char = (char*)calloc(num, sizeof(char*)); Am really confused!!!!! ---------- Post updated at 09:32 AM... (1 Reply)
Discussion started by: mind@work
1 Replies

6. Programming

Iterating and calloc questions.

Whilst creating the function readjust_descr I have stumble across what may be a problem or something that might just work. I was hoping someone could look at the code below and tell me if readjust_descr will clear all null pointers from the structure descr_list. struct descr descr_list =... (6 Replies)
Discussion started by: Errigour
6 Replies

7. Programming

calloc fails: 'Cannot allocate memory'

Hi , experts. I work on Linux station (RedHat 5.7), regular user, but have root password. %> uname -a Linux ran1log06 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux %> cat /etc/issue Red Hat Enterprise Linux Client release 5.7 (Tikanga) Kernel \r on... (5 Replies)
Discussion started by: baruchgu
5 Replies

8. Emergency UNIX and Linux Support

Memset fails on Solaris

Hi, memset call is failing on solaris for me. I wrote below code and that also fails. Any hints? void *memset(void *dst, int c, size_t n) { if (n) { char *d = dst; do { *d++ = c; } while (--n); } return dst; } (2 Replies)
Discussion started by: skyineyes
2 Replies
memccpy(3)						     Library Functions Manual							memccpy(3)

NAME
memccpy, memchr, memcmp, memcpy, memmove, memset - Perform memory operations LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <string.h> void *memccpy( void *s1, const void *s2, int c, size_t n); void *memchr( const void *s, int c, size_t n); int memcmp( const void *s1, const void *s2, size_t n); void *memcpy( void *s1, const void *s2, size_t n); void *memmove( void *s1, const void *s2, size_t n); void *memset( void *s, int c, size_t n); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: memchr(), memcmp(), memcpy(), memmove(), memset(): ISO C, XPG4, XPG4-UNIX memccpy(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the location of a string. Points to the location of a destination string. Points to the location of a source string. Specifies a character for which to search (except for memset(), in which c is the target of the copy). Specifies the number of characters to search. DESCRIPTION
The memccpy(), memchr(), memcmp(), memcpy(), memmove(), and memset() functions operate on strings in memory areas. A memory area is a group of contiguous characters bound by a count and not terminated by a null character. These memory functions do not check for overflow of the receiving memory area. All of the functions are declared in the string.h header file. The memccpy() function sequentially copies bytes from the location pointed to by the s2 parameter into the location pointed to by the s1 parameter until one of the following occurs: The character specified by the c parameter, which is converted to an unsigned char, is copied. The number of characters specified by the n parameter has been copied to the string at location s1. The memccpy() function returns a pointer to the character that follows character c in the string pointed to by s1. If character c is not encountered after n characters have been copied to the string at location s1, this function returns a null pointer. The memchr() function returns a pointer to the first occurrence of character (byte) c in the string pointed to by s. If character c is not encountered after n bytes have been copied to the string at location s, this function returns a null pointer. The memcmp() function compares the first n characters (bytes), which are converted to unsigned char, of the string pointed to by the s1 parameter with the first n characters (also interpreted as unsigned char) of the string pointed to by the s2 parameter. The memcmp() function returns 0 (zero) or a nonzero value to indicate the results of the comparison operation. The sign of a nonzero value is determined by the sign of the difference between the values of the first pair of bytes that differ in the strings being compared. Possi- ble return values and their meanings follow: When s1 is less than s2 When s1 is equal to s2 When s1 is greater than s2 The memcpy() function copies n bytes from the string pointed to by the s2 parameter into the location pointed to by the s1 parameter. When copying overlapping strings, the behavior of this function is unreliable. The memmove() function copies n bytes from the string at the location pointed to by the s2 parameter to the string at the location pointed to by the s1 parameter. Copying takes place as though the n number of bytes from string s2 were first copied into a temporary location having n bytes that do not overlap either of the strings pointed to by s1 and s2. Then, n number of bytes from the temporary location is copied to the string pointed to by s1. Consequently, this operation is nondestructive and proceeds from left to right. The memset() function copies the value of the byte specified by the c parameter, which is converted to an unsigned char, into each of the first n locations of the string pointed to by the s parameter. RETURN VALUES
The memccpy() function returns a pointer to the byte following the character (byte) specified by the c parameter in the string pointed to by the s1 parameter. If character c is not found after the number of bytes specified by the n parameter are scanned, the function returns a null pointer. The memchr() function returns a pointer to the character (byte) specified by the c parameter. If character c does not occur after n bytes in the string pointed to by the s parameter are scanned, the function returns a null pointer. The memcmp() function returns a value greater than, equal to, or less than 0 (zero), according to whether the string pointed to by the s1 parameter has a value greater than, equal to, or less than the string pointed to by the s2 parameter. The memcpy() and memmove() functions return the string pointed to by the s1 parameter. No return value is reserved to indicate an error. The memset() function returns the string pointed to by the s parameter. RELATED INFORMATION
Functions: bcopy(3), string(3), swab(3), wmemcpy(3) Standards: standards(5) delim off memccpy(3)
All times are GMT -4. The time now is 01:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy