String H
String H
Search: Go
Not logged in
C++
Discover more Programming Computer Science Software
Information
Tutorials
Reference programming language
Articles
Forum
header
Reference <cstring> (string.h)
C library:
<cassert> (assert.h) C Strings
<cctype> (ctype.h) This header file defines several functions to manipulate C strings and arrays.
<cerrno> (errno.h)
<cfenv> (fenv.h)
<cfloat> (float.h) Functions
<cinttypes> (inttypes.h) Copying:
<ciso646> (iso646.h)
memcpy Copy block of memory (function )
<climits> (limits.h)
<clocale> (locale.h) memmove Move block of memory (function )
<cmath> (math.h) strcpy Copy string (function )
<csetjmp> (setjmp.h)
<csignal> (signal.h) strncpy Copy characters from string (function )
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) Concatenation:
<cstddef> (stddef.h) strcat Concatenate strings (function )
<cstdint> (stdint.h)
strncat Append characters from string (function )
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h) Comparison:
<ctgmath> (tgmath.h) memcmp Compare two blocks of memory (function )
<ctime> (time.h) strcmp Compare two strings (function )
<cuchar> (uchar.h)
<cwchar> (wchar.h) strcoll Compare two strings using locale (function )
<cwctype> (wctype.h) strncmp Compare characters of two strings (function )
Containers:
strxfrm Transform string using locale (function )
Input/Output:
Multi-threading:
Searching:
Other:
memchr Locate character in block of memory (function )
<cstring> (string.h)
strchr Locate first occurrence of character in string (function )
functions:
memchr strcspn Get span until character in string (function )
memcmp strpbrk Locate characters in string (function )
memcpy
strrchr Locate last occurrence of character in string (function )
memmove
memset strspn Get span of character set in string (function )
strcat strstr Locate substring (function )
strchr
strcmp strtok Split string into tokens (function )
strcoll
strcpy Other:
strcspn memset Fill block of memory (function )
strerror
strerror Get pointer to error message string (function )
strlen
strncat strlen Get string length (function )
strncmp
strncpy
strpbrk Macros
strrchr
NULL Null pointer (macro )
strspn
strstr
strtok
strxfrm Types
types: size_t Unsigned integral type (type )
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more programming language Computer Science Programming
Information
Tutorials
Reference Software
Articles
Forum
function
Reference memcpy <cstring>
C library:
void * memcpy ( void * destination, const void * source, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Copy block of memory
<cerrno> (errno.h) Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by
<cfenv> (fenv.h) destination.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The underlying type of the objects pointed to by both the source and destination pointers are irrelevant for this
<ciso646> (iso646.h) function; The result is a binary copy of the data.
<climits> (limits.h)
The function does not check for any terminating null character in source - it always copies exactly num bytes.
<clocale> (locale.h)
<cmath> (math.h)
To avoid overflows, the size of the arrays pointed to by both the destination and source parameters, shall be at least
<csetjmp> (setjmp.h)
num bytes, and should not overlap (for overlapping memory blocks, memmove is a safer approach).
<csignal> (signal.h)
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) Parameters
<cstddef> (stddef.h)
<cstdint> (stdint.h) destination
<cstdio> (stdio.h) Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
<cstdlib> (stdlib.h)
source
<cstring> (string.h)
Pointer to the source of data to be copied, type-casted to a pointer of type const void*.
<ctgmath> (tgmath.h)
<ctime> (time.h) num
<cuchar> (uchar.h) Number of bytes to copy.
<cwchar> (wchar.h) size_t is an unsigned integral type.
<cwctype> (wctype.h)
Containers:
Input/Output:
Return Value
Multi-threading:
Other: destination is returned.
<cstring> (string.h)
functions: Example
memchr 1 /* memcpy example */
memcmp 2 #include <stdio.h>
memcpy 3 #include <string.h>
memmove 4
memset 5 struct {
6 char name[40];
strcat
7 int age;
strchr 8 } person, person_copy;
strcmp 9
strcoll 10 int main ()
strcpy 11 {
strcspn 12 char myname[] = "Pierre de Fermat";
Edit & Run
strerror 13
14 /* using memcpy to copy string: */
strlen
15 memcpy ( [Link], myname, strlen(myname)+1 );
strncat 16 [Link] = 46;
strncmp 17
strncpy 18 /* using memcpy to copy structure: */
strpbrk 19 memcpy ( &person_copy, &person, sizeof(person) );
strrchr 20
strspn 21 printf ("person_copy: %s, %d \n", person_copy.name, person_copy.age );
22
strstr
23 return 0;
strtok 24 }
strxfrm
types:
size_t
Output:
macro constants:
NULL
person_copy: Pierre de Fermat, 46
C++
Discover more C & C++ Computer Science Programming Software
Information
Tutorials
Reference programming language
Articles
Forum
function
Reference memmove <cstring>
C library:
void * memmove ( void * destination, const void * source, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Move block of memory
<cerrno> (errno.h) Copies the values of num bytes from the location pointed by source to the memory block pointed by destination.
<cfenv> (fenv.h) Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function;
<ciso646> (iso646.h) The result is a binary copy of the data.
<climits> (limits.h)
<clocale> (locale.h)
The function does not check for any terminating null character in source - it always copies exactly num bytes.
<cmath> (math.h)
To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least num
<csetjmp> (setjmp.h)
bytes.
<csignal> (signal.h)
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) Parameters
<cstddef> (stddef.h)
<cstdint> (stdint.h) destination
<cstdio> (stdio.h) Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
<cstdlib> (stdlib.h)
source
<cstring> (string.h)
Pointer to the source of data to be copied, type-casted to a pointer of type const void*.
<ctgmath> (tgmath.h)
<ctime> (time.h) num
<cuchar> (uchar.h) Number of bytes to copy.
<cwchar> (wchar.h) size_t is an unsigned integral type.
<cwctype> (wctype.h)
Containers:
Input/Output:
Return Value
Multi-threading:
Other: destination is returned.
<cstring> (string.h)
functions: Example
memchr 1 /* memmove example */
memcmp 2 #include <stdio.h>
memcpy 3 #include <string.h>
memmove 4
memset 5 int main ()
6 { Edit & Run
strcat
7 char str[] = "memmove can be very useful......";
strchr 8 memmove (str+20,str+15,11);
strcmp 9 puts (str);
strcoll 10 return 0;
strcpy 11 }
strcspn
strerror
strlen Output:
strncat
strncmp memmove can be very very useful.
strncpy
strpbrk
strrchr See also
strspn
strstr
memcpy Copy block of memory (function )
strtok memchr Locate character in block of memory (function )
strxfrm
memcmp Compare two blocks of memory (function )
types:
size_t memset Fill block of memory (function )
macro constants: strncpy Copy characters from string (function )
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Computer Science Programming Software
Information
Tutorials
Reference programming language
Articles
Forum
function
Reference strcpy <cstring>
C library:
char * strcpy ( char * destination, const char * source );
<cassert> (assert.h)
<cctype> (ctype.h) Copy string
<cerrno> (errno.h) Copies the C string pointed by source into the array pointed by destination, including the terminating null character
<cfenv> (fenv.h) (and stopping at that point).
<cfloat> (float.h)
<cinttypes> (inttypes.h) To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as
<ciso646> (iso646.h) source (including the terminating null character), and should not overlap in memory with source.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) destination
<csignal> (signal.h) Pointer to the destination array where the content is to be copied.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) source
<cstddef> (stddef.h) C string to be copied.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Return Value
<cstring> (string.h)
<ctgmath> (tgmath.h)
destination is returned.
<ctime> (time.h)
<cuchar> (uchar.h)
Example
<cwchar> (wchar.h)
<cwctype> (wctype.h) 1 /* strcpy example */
Containers: 2 #include <stdio.h>
Input/Output: 3 #include <string.h>
4
Multi-threading:
5 int main ()
Other: 6 {
7 char str1[]="Sample string";
<cstring> (string.h) Edit & Run
8 char str2[40];
functions: 9 char str3[40];
memchr 10 strcpy (str2,str1);
memcmp 11 strcpy (str3,"copy successful");
memcpy 12 printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
memmove
13 return 0;
14 }
memset
strcat
strchr
strcmp
Output:
strcoll
strcpy
str1: Sample string
str2: Sample string
strcspn
str3: copy successful
strerror
strlen
strncat
See also
strncmp
strncpy strncpy Copy characters from string (function )
strpbrk memcpy Copy block of memory (function )
strrchr
strspn memmove Move block of memory (function )
strstr memchr Locate character in block of memory (function )
strtok
memcmp Compare two blocks of memory (function )
strxfrm
types: memset Fill block of memory (function )
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more programming language Computer Science Programming
Information
Tutorials
Reference Software
Articles
Forum
function
Reference strncpy <cstring>
C library:
char * strncpy ( char * destination, const char * source, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Copy characters from string
<cerrno> (errno.h) Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-
<cfenv> (fenv.h) character) is found before num characters have been copied, destination is padded with zeros until a total of num
<cfloat> (float.h) characters have been written to it.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h) No null-character is implicitly appended at the end of destination if source is longer than num. Thus, in this case,
<climits> (limits.h) destination shall not be considered a null terminated C string (reading it as such would overflow).
<clocale> (locale.h)
destination and source shall not overlap (see memmove for a safer alternative when overlapping).
<cmath> (math.h)
<csetjmp> (setjmp.h)
<csignal> (signal.h)
Parameters
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) destination
<cstddef> (stddef.h) Pointer to the destination array where the content is to be copied.
<cstdint> (stdint.h)
source
<cstdio> (stdio.h)
C string to be copied.
<cstdlib> (stdlib.h)
<cstring> (string.h) num
<ctgmath> (tgmath.h) Maximum number of characters to be copied from source.
<ctime> (time.h) size_t is an unsigned integral type.
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h)
Return Value
Containers:
Input/Output: destination is returned.
Multi-threading:
Other:
Example
<cstring> (string.h)
1 /* strncpy example */
functions: 2 #include <stdio.h>
memchr 3 #include <string.h>
memcmp 4
memcpy 5 int main ()
memmove 6 {
7 char str1[]= "To be or not to be";
memset
8 char str2[40];
strcat 9 char str3[40];
strchr 10
strcmp 11 /* copy to sized buffer (overflow safe): */
strcoll 12 strncpy ( str2, str1, sizeof(str2) ); Edit & Run
strcpy 13
strcspn 14 /* partial copy (only 5 chars): */
15 strncpy ( str3, str2, 5 );
strerror
16 str3[5] = '\0'; /* null character manually added */
strlen 17
strncat 18 puts (str1);
strncmp 19 puts (str2);
strncpy 20 puts (str3);
strpbrk 21
strrchr 22 return 0;
23 }
strspn
strstr
strtok
strxfrm Output:
types:
size_t To be or not to be
To be or not to be
macro constants:
To be
NULL
Discover more
See also
strcpy Copy string (function )
memcpy Copy block of memory (function )
memmove Move block of memory (function )
memchr Locate character in block of memory (function )
memcmp Compare two blocks of memory (function )
memset Fill block of memory (function )
C++
Discover more Software programming language Programming
Information
Tutorials
Reference Computer Science
Articles
Forum
function
Reference strcat <cstring>
C library:
char * strcat ( char * destination, const char * source );
<cassert> (assert.h)
<cctype> (ctype.h) Concatenate strings
<cerrno> (errno.h) Appends a copy of the source string to the destination string. The terminating null character in destination is
<cfenv> (fenv.h) overwritten by the first character of source, and a null-character is included at the end of the new string formed by the
<cfloat> (float.h) concatenation of both in destination.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h) destination and source shall not overlap.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) destination
<csignal> (signal.h) Pointer to the destination array, which should contain a C string, and be large enough to contain the
<cstdarg> (stdarg.h) concatenated resulting string.
<cstdbool> (stdbool.h)
<cstddef> (stddef.h) source
<cstdint> (stdint.h)
C string to be appended. This should not overlap destination.
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h) Return Value
<ctgmath> (tgmath.h)
destination is returned.
<ctime> (time.h)
<cuchar> (uchar.h)
<cwchar> (wchar.h)
Example
<cwctype> (wctype.h)
Containers: 1 /* strcat example */
Input/Output: 2 #include <stdio.h>
3 #include <string.h>
Multi-threading:
4
Other:
5 int main ()
6 {
<cstring> (string.h)
7 char str[80];
functions: Edit & Run
8 strcpy (str,"these ");
memchr 9 strcat (str,"strings ");
memcmp 10 strcat (str,"are ");
memcpy 11 strcat (str,"concatenated.");
memmove 12 puts (str);
13 return 0;
memset
14 }
strcat
strchr
strcmp
Output:
strcoll
strcpy
these strings are concatenated.
strcspn
strerror
strlen
strncat See also
strncmp strncat Append characters from string (function )
strncpy
strcpy Copy string (function )
strpbrk
strrchr memcpy Copy block of memory (function )
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Software Programming programming language
Information
Tutorials
Reference Computer Science
Articles
Forum
function
Reference strncat <cstring>
C library:
char * strncat ( char * destination, const char * source, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Append characters from string
<cerrno> (errno.h) Appends the first num characters of source to destination, plus a terminating null-character.
<cfenv> (fenv.h)
<cfloat> (float.h) If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h)
<climits> (limits.h) Parameters
<clocale> (locale.h)
destination
<cmath> (math.h)
Pointer to the destination array, which should contain a C string, and be large enough to contain the
<csetjmp> (setjmp.h) concatenated resulting string, including the additional null-character.
<csignal> (signal.h)
<cstdarg> (stdarg.h) source
<cstdbool> (stdbool.h) C string to be appended.
<cstddef> (stddef.h) num
<cstdint> (stdint.h) Maximum number of characters to be appended.
<cstdio> (stdio.h) size_t is an unsigned integral type.
<cstdlib> (stdlib.h)
<cstring> (string.h)
<ctgmath> (tgmath.h)
<ctime> (time.h) Return Value
<cuchar> (uchar.h) destination is returned.
<cwchar> (wchar.h)
<cwctype> (wctype.h)
Containers: Example
Input/Output:
1 /* strncat example */
Multi-threading: 2 #include <stdio.h>
Other: 3 #include <string.h>
4
<cstring> (string.h) 5 int main ()
functions: 6 {
memchr 7 char str1[20];
8 Edit & Run
memcmp char str2[20];
9 strcpy (str1,"To be ");
memcpy
10 strcpy (str2,"or not to be");
memmove 11 strncat (str1, str2, 6);
memset 12 puts (str1);
strcat 13 return 0;
strchr 14 }
strcmp
strcoll
strcpy Output:
strcspn
strerror To be or not
strlen
strncat
strncmp See also
strncpy
strcat Concatenate strings (function )
strpbrk
strrchr strncpy Copy characters from string (function )
strspn
memcpy Copy block of memory (function )
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Programming Computer Science programming language
Information
Tutorials
Reference Software
Articles
Forum
function
Reference memcmp <cstring>
C library:
int memcmp ( const void * ptr1, const void * ptr2, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Compare two blocks of memory
<cerrno> (errno.h) Compares the first num bytes of the block of memory pointed by ptr1 to the first num bytes pointed by ptr2, returning
<cfenv> (fenv.h) zero if they all match or a value different from zero representing which is greater if they do not.
<cfloat> (float.h)
<cinttypes> (inttypes.h) Notice that, unlike strcmp, the function does not stop comparing after finding a null character.
<ciso646> (iso646.h)
<climits> (limits.h)
<clocale> (locale.h) Parameters
<cmath> (math.h)
ptr1
<csetjmp> (setjmp.h) Pointer to block of memory.
<csignal> (signal.h)
<cstdarg> (stdarg.h) ptr2
<cstdbool> (stdbool.h) Pointer to block of memory.
<cstddef> (stddef.h) num
<cstdint> (stdint.h) Number of bytes to compare.
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h)
<ctgmath> (tgmath.h) Return Value
<ctime> (time.h) Returns an integral value indicating the relationship between the content of the memory blocks:
<cuchar> (uchar.h) return
<cwchar> (wchar.h) indicates
value
<cwctype> (wctype.h) the first byte that does not match in both memory blocks has a lower value in ptr1 than in ptr2 (if
Containers: <0
evaluated as unsigned char values)
Input/Output: 0 the contents of both memory blocks are equal
Multi-threading:
the first byte that does not match in both memory blocks has a greater value in ptr1 than in ptr2 (if
Other: >0
evaluated as unsigned char values)
<cstring> (string.h)
functions:
memchr
Example
memcmp 1 /* memcmp example */
memcpy 2 #include <stdio.h>
memmove 3 #include <string.h>
4
memset
5 int main ()
strcat
6 {
strchr 7 char buffer1[] = "DWgaOtP12df0";
strcmp 8 char buffer2[] = "DWGAOTP12DF0";
strcoll 9
strcpy 10 int n; Edit & Run
strcspn 11
strerror
12 n=memcmp ( buffer1, buffer2, sizeof(buffer1) );
13
strlen
14 if (n>0) printf ("'%s' is greater than '%s'.\n",buffer1,buffer2);
strncat 15 else if (n<0) printf ("'%s' is less than '%s'.\n",buffer1,buffer2);
strncmp 16 else printf ("'%s' is the same as '%s'.\n",buffer1,buffer2);
strncpy 17
strpbrk 18 return 0;
strrchr 19 }
strspn
strstr
strtok Output:
strxfrm
types: 'DWgaOtP12df0' is greater than 'DWGAOTP12DF0'.
size_t
macro constants: DWgAOtp12Df0 is greater than DWGAOTP12DF0 because the first non-matching character in both words are 'g' and 'G'
NULL respectively, and 'g' (103) evaluates as greater than 'G' (71).
Discover more
See also
strcmp Compare two strings (function )
memchr Locate character in block of memory (function )
memcpy Copy block of memory (function )
memset Fill block of memory (function )
strncmp Compare characters of two strings (function )
C++
Discover more Programming programming language Computer Science
Information
Tutorials
Reference Software
Articles
Forum
function
Reference strcmp <cstring>
C library:
int strcmp ( const char * str1, const char * str2 );
<cassert> (assert.h)
<cctype> (ctype.h) Compare two strings
<cerrno> (errno.h) Compares the C string str1 to the C string str2.
<cfenv> (fenv.h)
<cfloat> (float.h) This function starts comparing the first character of each string. If they are equal to each other, it continues with the
<cinttypes> (inttypes.h) following pairs until the characters differ or until a terminating null-character is reached.
<ciso646> (iso646.h)
<climits> (limits.h) This function performs a binary comparison of the characters. For a function that takes into account locale-specific
rules, see strcoll.
<clocale> (locale.h)
<cmath> (math.h)
<csetjmp> (setjmp.h)
Parameters
<csignal> (signal.h)
<cstdarg> (stdarg.h) str1
<cstdbool> (stdbool.h) C string to be compared.
<cstddef> (stddef.h)
str2
<cstdint> (stdint.h)
C string to be compared.
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h)
<ctgmath> (tgmath.h) Return Value
<ctime> (time.h)
Returns an integral value indicating the relationship between the strings:
<cuchar> (uchar.h)
return value indicates
<cwchar> (wchar.h)
<cwctype> (wctype.h) <0 the first character that does not match has a lower value in ptr1 than in ptr2
Containers: 0 the contents of both strings are equal
Input/Output: >0 the first character that does not match has a greater value in ptr1 than in ptr2
Multi-threading:
Other:
Example
<cstring> (string.h)
1 #include <stdio.h>
functions:
2 #include <string.h>
memchr 3
memcmp 4 int main ()
memcpy 5 {
memmove 6 char key[] = "apple";
memset 7 char buffer[80];
strcat 8 do { Edit & Run
9 printf ("Guess my favorite fruit? ");
strchr
10 fflush (stdout);
strcmp 11 scanf ("%79s",buffer);
strcoll 12 } while (strcmp (key,buffer) != 0);
strcpy 13 puts ("Correct answer!");
strcspn 14 return 0;
strerror 15 }
strlen
strncat
strncmp Output:
strncpy
strpbrk Guess my favourite fruit? orange
strrchr Guess my favourite fruit? apple
strspn Correct answer!
strstr
strtok
strxfrm See also
types: strncmp Compare characters of two strings (function )
size_t
memcmp Compare two blocks of memory (function )
macro constants:
NULL strrchr Locate last occurrence of character in string (function )
strspn Get span of character set in string (function )
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Computer Science Software C & C++ Programming
Information
Tutorials
Reference programming language
Articles
Forum
function
Reference strcoll <cstring>
C library:
int strcoll ( const char * str1, const char * str2 );
<cassert> (assert.h)
<cctype> (ctype.h) Compare two strings using locale
<cerrno> (errno.h) Compares the C string str1 to the C string str2, both interpreted appropriately according to the LC_COLLATE category of
<cfenv> (fenv.h) the C locale currently selected.
<cfloat> (float.h)
<cinttypes> (inttypes.h) This function starts comparing the first character of each string. If they are equal to each other continues with the
<ciso646> (iso646.h) following pair until the characters differ or until a null-character signaling the end of a string is reached.
<climits> (limits.h)
<clocale> (locale.h)
The behavior of this function depends on the LC_COLLATE category of the selected C locale.
<cmath> (math.h)
<csetjmp> (setjmp.h)
Parameters
<csignal> (signal.h)
<cstdarg> (stdarg.h) str1
<cstdbool> (stdbool.h) C string to be compared.
<cstddef> (stddef.h)
<cstdint> (stdint.h)
str2
C string to be compared.
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h)
<ctgmath> (tgmath.h) Return Value
<ctime> (time.h)
Returns an integral value indicating the relationship between the strings:
<cuchar> (uchar.h)
A zero value indicates that both strings are equal.
<cwchar> (wchar.h)
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2;
<cwctype> (wctype.h) And a value less than zero indicates the opposite.
Containers:
Input/Output:
Multi-threading: See also
Other:
strcmp Compare two strings (function )
<cstring> (string.h) strncmp Compare characters of two strings (function )
functions:
memcmp Compare two blocks of memory (function )
memchr
memcmp
memcpy
memmove
memset
strcat
strchr
strcmp
strcoll
strcpy
strcspn
strerror
strlen
strncat
strncmp
strncpy
strpbrk
strrchr
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
C++
Discover more programming language Programming Software
Information
Tutorials
Reference Computer Science
Articles
Forum
function
Reference strncmp <cstring>
C library:
int strncmp ( const char * str1, const char * str2, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Compare characters of two strings
<cerrno> (errno.h) Compares up to num characters of the C string str1 to those of the C string str2.
<cfenv> (fenv.h) This function starts comparing the first character of each string. If they are equal to each other, it continues with the
<cfloat> (float.h) following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in
<cinttypes> (inttypes.h) both strings, whichever happens first.
<ciso646> (iso646.h)
<climits> (limits.h)
<clocale> (locale.h) Parameters
<cmath> (math.h)
str1
<csetjmp> (setjmp.h) C string to be compared.
<csignal> (signal.h)
<cstdarg> (stdarg.h) str2
<cstdbool> (stdbool.h) C string to be compared.
<cstddef> (stddef.h) num
<cstdint> (stdint.h) Maximum number of characters to compare.
<cstdio> (stdio.h) size_t is an unsigned integral type.
<cstdlib> (stdlib.h)
<cstring> (string.h)
<ctgmath> (tgmath.h)
<ctime> (time.h) Return Value
<cuchar> (uchar.h) Returns an integral value indicating the relationship between the strings:
<cwchar> (wchar.h) return value indicates
<cwctype> (wctype.h) <0 the first character that does not match has a lower value in str1 than in str2
Containers:
0 the contents of both strings are equal
Input/Output:
>0 the first character that does not match has a greater value in str1 than in str2
Multi-threading:
Other:
C++
Discover more programming language Software Computer Science
Information
Tutorials
Reference Programming
Articles
Forum
function
Reference strxfrm <cstring>
C library:
size_t strxfrm ( char * destination, const char * source, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Transform string using locale
<cerrno> (errno.h) Transforms the C string pointed by source according to the current locale and copies the first num characters of the
<cfenv> (fenv.h) transformed string to destination, returning its length.
<cfloat> (float.h) Alternativelly, the function can be used to only retrieve the length, by specifying a null pointer for destination and zero
<cinttypes> (inttypes.h) for num.
<ciso646> (iso646.h)
<climits> (limits.h) destination and source shall not overlap.
<clocale> (locale.h)
The behavior of this function depends on the LC_COLLATE category of the selected C locale.
<cmath> (math.h)
<csetjmp> (setjmp.h)
<csignal> (signal.h)
Parameters
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) destination
<cstddef> (stddef.h) Pointer to the destination array where the content is to be copied.
<cstdint> (stdint.h) It can be a null pointer if the argument for num is zero.
<cstdio> (stdio.h)
source
<cstdlib> (stdlib.h)
C string to be transformed.
<cstring> (string.h)
<ctgmath> (tgmath.h) num
<ctime> (time.h) Maximum number of characters to be copied to destination.
<cuchar> (uchar.h) size_t is an unsigned integral type.
<cwchar> (wchar.h)
<cwctype> (wctype.h)
Containers:
Return Value
Input/Output:
Multi-threading: The length of the transformed string, not including the terminating null-character.
Other: size_t is an unsigned integral type.
<cstring> (string.h)
functions: See also
memchr strncpy Copy characters from string (function )
memcmp
strncmp Compare characters of two strings (function )
memcpy
memmove strcoll Compare two strings using locale (function )
memset
strcat
strchr
strcmp
strcoll
strcpy
strcspn
strerror
strlen
strncat
strncmp
strncpy
strpbrk
strrchr
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
C++
Discover more Computer Science Programming Software
Information
Tutorials
Reference programming language
Articles
Forum
function
Reference memchr <cstring>
C library:
const void * memchr ( const void * ptr, int value, size_t num );
<cassert> (assert.h)
void * memchr ( void * ptr, int value, size_t num );
<cctype> (ctype.h)
<cerrno> (errno.h)
Locate character in block of memory
<cfenv> (fenv.h) Searches within the first num bytes of the block of memory pointed by ptr for the first occurrence of value (interpreted
<cfloat> (float.h) as an unsigned char), and returns a pointer to it.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h) Both value and each of the bytes checked on the the ptr array are interpreted as unsigned char for the comparison.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) ptr
<csignal> (signal.h) Pointer to the block of memory where the search is performed.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) value
Value to be located. The value is passed as an int, but the function performs a byte per byte search using the
<cstddef> (stddef.h)
unsigned char conversion of this value.
<cstdint> (stdint.h)
<cstdio> (stdio.h) num
<cstdlib> (stdlib.h) Number of bytes to be analyzed.
<cstring> (string.h) size_t is an unsigned integral type.
<ctgmath> (tgmath.h)
<ctime> (time.h)
<cuchar> (uchar.h)
<cwchar> (wchar.h)
Return Value
<cwctype> (wctype.h) A pointer to the first occurrence of value in the block of memory pointed by ptr.
Containers: If the value is not found, the function returns a null pointer.
Input/Output:
Multi-threading:
Other: Portability
In C, this function is only declared as:
<cstring> (string.h)
functions: void * memchr ( const void *, int, size_t );
memchr
memcmp instead of the two overloaded versions provided in C++.
memcpy
memmove
memset Example
strcat 1 /* memchr example */
strchr 2 #include <stdio.h>
strcmp 3 #include <string.h>
strcoll 4
strcpy 5 int main ()
6 {
strcspn
7 char * pch;
strerror
8 char str[] = "Example string"; Edit & Run
strlen 9 pch = (char*) memchr (str, 'p', strlen(str));
strncat 10 if (pch!=NULL)
strncmp 11 printf ("'p' found at position %d.\n", pch-str+1);
strncpy 12 else
strpbrk 13 printf ("'p' not found.\n");
14 return 0;
strrchr
15 }
strspn
strstr
strtok
Output:
strxfrm
types:
'p' found at position 5.
size_t
macro constants:
NULL
See also
Discover more memcmp Compare two blocks of memory (function )
strchr Locate first occurrence of character in string (function )
strrchr Locate last occurrence of character in string (function )
C++
Discover more Programming Computer Science programming language
Information
Tutorials
Reference Software
Articles
Forum
function
Reference strchr <cstring>
C library:
const char * strchr ( const char * str, int character );
<cassert> (assert.h)
char * strchr ( char * str, int character );
<cctype> (ctype.h)
<cerrno> (errno.h)
Locate first occurrence of character in string
<cfenv> (fenv.h) Returns a pointer to the first occurrence of character in the C string str.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The terminating null-character is considered part of the C string. Therefore, it can also be located in order to retrieve a
<ciso646> (iso646.h) pointer to the end of a string.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) str
<csignal> (signal.h) C string.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) character
Character to be located. It is passed as its int promotion, but it is internally converted back to char for the
<cstddef> (stddef.h)
comparison.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h) Return Value
<ctgmath> (tgmath.h)
A pointer to the first occurrence of character in str.
<ctime> (time.h)
If the character is not found, the function returns a null pointer.
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h) Portability
Containers:
In C, this function is only declared as:
Input/Output:
Multi-threading:
char * strchr ( const char *, int );
Other:
C++
Discover more Software Computer Science Programming
Information
Tutorials
Reference programming language
Articles
Forum
function
Reference strcspn <cstring>
C library:
size_t strcspn ( const char * str1, const char * str2 );
<cassert> (assert.h)
<cctype> (ctype.h) Get span until character in string
<cerrno> (errno.h) Scans str1 for the first occurrence of any of the characters that are part of str2, returning the number of characters of
<cfenv> (fenv.h) str1 read before this first occurrence.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The search includes the terminating null-characters. Therefore, the function will return the length of str1 if none of the
<ciso646> (iso646.h) characters of str2 are found in str1.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) str1
<csignal> (signal.h) C string to be scanned.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) str2
<cstddef> (stddef.h) C string containing the characters to match.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Return value
<cstring> (string.h)
<ctgmath> (tgmath.h)
The length of the initial part of str1 not containing any of the characters that are part of str2.
This is the length of str1 if none of the characters in str2 are found in str1.
<ctime> (time.h)
size_t is an unsigned integral type.
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h)
Example
Containers:
Input/Output: 1 /* strcspn example */
Multi-threading: 2 #include <stdio.h>
3 #include <string.h>
Other:
4
<cstring> (string.h) 5 int main ()
6 {
functions: 7 char str[] = "fcba73"; Edit & Run
memchr 8 char keys[] = "1234567890";
memcmp 9 int i;
memcpy 10 i = strcspn (str,keys);
memmove 11 printf ("The first number in str is at position %d.\n",i+1);
memset
12 return 0;
13 }
strcat
strchr
strcmp
Output:
strcoll
strcpy
The first number in str is at position 5
strcspn
strerror
strlen
strncat See also
strncmp strpbrk Locate characters in string (function )
strncpy
strspn Get span of character set in string (function )
strpbrk
strrchr strstr Locate substring (function )
strspn strncmp Compare characters of two strings (function )
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more programming language Software Programming
Information
Tutorials
Reference Computer Science
Articles
Forum
function
Reference strpbrk <cstring>
C library:
const char * strpbrk ( const char * str1, const char * str2 );
<cassert> (assert.h)
char * strpbrk ( char * str1, const char * str2 );
<cctype> (ctype.h)
<cerrno> (errno.h)
Locate characters in string
<cfenv> (fenv.h) Returns a pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if there
<cfloat> (float.h) are no matches.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h) The search does not include the terminating null-characters of either strings, but ends there.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) str1
<csignal> (signal.h) C string to be scanned.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) str2
C string containing the characters to match.
<cstddef> (stddef.h)
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Return Value
<cstring> (string.h)
A pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if none of the
<ctgmath> (tgmath.h)
characters of str2 is found in str1 before the terminating null-character.
<ctime> (time.h)
If none of the characters of str2 is present in str1, a null pointer is returned.
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h) Portability
Containers:
In C, this function is only declared as:
Input/Output:
Multi-threading:
char * strpbrk ( const char *, const char * );
Other:
C++
Discover more Software Computer Science programming language
Information
Tutorials
Reference Programming
Articles
Forum
function
Reference strrchr <cstring>
C library:
const char * strrchr ( const char * str, int character );
<cassert> (assert.h)
char * strrchr ( char * str, int character );
<cctype> (ctype.h)
<cerrno> (errno.h)
Locate last occurrence of character in string
<cfenv> (fenv.h) Returns a pointer to the last occurrence of character in the C string str.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The terminating null-character is considered part of the C string. Therefore, it can also be located to retrieve a pointer
<ciso646> (iso646.h) to the end of a string.
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
Parameters
<csetjmp> (setjmp.h) str
<csignal> (signal.h) C string.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) character
<cstddef> (stddef.h)
Character to be located. It is passed as its int promotion, but it is internally converted back to char.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Return Value
<cstring> (string.h)
A pointer to the last occurrence of character in str.
<ctgmath> (tgmath.h)
If the character is not found, the function returns a null pointer.
<ctime> (time.h)
<cuchar> (uchar.h)
<cwchar> (wchar.h)
Portability
<cwctype> (wctype.h)
Containers: In C, this function is only declared as:
Input/Output:
char * strrchr ( const char *, int );
Multi-threading:
Other:
instead of the two overloaded versions provided in C++.
<cstring> (string.h)
functions:
Example
memchr
memcmp 1 /* strrchr example */
memcpy 2 #include <stdio.h>
memmove 3 #include <string.h>
4
memset
5 int main ()
strcat 6 {
strchr 7 Edit & Run
char str[] = "This is a sample string";
strcmp 8 char * pch;
strcoll 9 pch=strrchr(str,'s');
strcpy 10 printf ("Last occurence of 's' found at %d \n",pch-str+1);
strcspn 11 return 0;
12 }
strerror
strlen
strncat
strncmp Output:
strncpy
strpbrk Last occurrence of 's' found at 18
strrchr
strspn
strstr See also
strtok strchr Locate first occurrence of character in string (function )
strxfrm
memchr Locate character in block of memory (function )
types:
size_t strpbrk Locate characters in string (function )
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Computer Science Programming programming language
Information
Tutorials
Reference Software
Articles
Forum
function
Reference strspn <cstring>
C library:
size_t strspn ( const char * str1, const char * str2 );
<cassert> (assert.h)
<cctype> (ctype.h) Get span of character set in string
<cerrno> (errno.h) Returns the length of the initial portion of str1 which consists only of characters that are part of str2.
<cfenv> (fenv.h)
<cfloat> (float.h) The search does not include the terminating null-characters of either strings, but ends there.
<cinttypes> (inttypes.h)
<ciso646> (iso646.h)
<climits> (limits.h) Parameters
<clocale> (locale.h)
str1
<cmath> (math.h)
C string to be scanned.
<csetjmp> (setjmp.h)
<csignal> (signal.h) str2
<cstdarg> (stdarg.h) C string containing the characters to match.
<cstdbool> (stdbool.h)
<cstddef> (stddef.h)
<cstdint> (stdint.h)
Return value
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) The length of the initial portion of str1 containing only characters that appear in str2.
<cstring> (string.h) Therefore, if all of the characters in str1 are in str2, the function returns the length of the entire str1 string, and if the
<ctgmath> (tgmath.h)
first character in str1 is not in str2, the function returns zero.
size_t is an unsigned integral type.
<ctime> (time.h)
<cuchar> (uchar.h)
<cwchar> (wchar.h)
Example
<cwctype> (wctype.h)
Containers: 1 /* strspn example */
Input/Output: 2 #include <stdio.h>
3 #include <string.h>
Multi-threading:
4
Other:
5 int main ()
6 {
<cstring> (string.h)
7 int i;
functions: 8 char strtext[] = "129th"; Edit & Run
memchr 9 char cset[] = "1234567890";
memcmp 10
memcpy 11 i = strspn (strtext,cset);
memmove 12 printf ("The initial number has %d digits.\n",i);
13 return 0;
memset
14 }
strcat 15
strchr
strcmp
strcoll Output:
strcpy
strcspn The initial number has 3 digits.
strerror
strlen
strncat
See also
strncmp
strncpy strcspn Get span until character in string (function )
strpbrk strstr Locate substring (function )
strrchr
strncmp Compare characters of two strings (function )
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Computer Science programming language Programming
Information
Tutorials
Reference Software
Articles
Forum
function
Reference strstr <cstring>
C library:
const char * strstr ( const char * str1, const char * str2 );
<cassert> (assert.h)
char * strstr ( char * str1, const char * str2 );
<cctype> (ctype.h)
<cerrno> (errno.h)
Locate substring
<cfenv> (fenv.h) Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The matching process does not include the terminating null-characters, but it stops there.
<ciso646> (iso646.h)
<climits> (limits.h)
<clocale> (locale.h)
Parameters
<cmath> (math.h) str1
<csetjmp> (setjmp.h) C string to be scanned.
<csignal> (signal.h)
<cstdarg> (stdarg.h) str2
<cstdbool> (stdbool.h) C string containing the sequence of characters to match.
<cstddef> (stddef.h)
<cstdint> (stdint.h)
<cstdio> (stdio.h) Return Value
<cstdlib> (stdlib.h)
A pointer to the first occurrence in str1 of the entire sequence of characters specified in str2, or a null pointer if the
<cstring> (string.h)
sequence is not present in str1.
<ctgmath> (tgmath.h)
<ctime> (time.h)
<cuchar> (uchar.h)
Portability
<cwchar> (wchar.h)
<cwctype> (wctype.h) In C, this function is only declared as:
Containers:
char * strstr ( const char *, const char * );
Input/Output:
Multi-threading:
instead of the two overloaded versions provided in C++.
Other:
<cstring> (string.h)
functions:
Example
memchr 1 /* strstr example */
memcmp 2 #include <stdio.h>
memcpy 3 #include <string.h>
4
memmove
5 int main ()
memset
6 {
strcat 7 char str[] ="This is a simple string";
strchr 8 Edit & Run
char * pch;
strcmp 9 pch = strstr (str,"simple");
strcoll 10 if (pch != NULL)
strcpy 11 strncpy (pch,"sample",6);
12 puts (str);
strcspn
13 return 0;
strerror
14 }
strlen
strncat
This example searches for the "simple" substring in str and replaces that word for "sample".
strncmp
strncpy
Output:
strpbrk
strrchr
This is a sample string
strspn
strstr
strtok
strxfrm
See also
types: strspn Get span of character set in string (function )
size_t
strpbrk Locate characters in string (function )
macro constants:
NULL strchr Locate first occurrence of character in string (function )
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Programming Software programming language
Information
Tutorials
Reference Computer Science
Articles
Forum
function
Reference strtok <cstring>
C library:
char * strtok ( char * str, const char * delimiters );
<cassert> (assert.h)
<cctype> (ctype.h) Split string into tokens
<cerrno> (errno.h) A sequence of calls to this function split str into tokens, which are sequences of contiguous characters separated by any
<cfenv> (fenv.h) of the characters that are part of delimiters.
<cfloat> (float.h)
<cinttypes> (inttypes.h) On a first call, the function expects a C string as argument for str, whose first character is used as the starting location
<ciso646> (iso646.h) to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of
<climits> (limits.h) the last token as the new starting location for scanning.
<clocale> (locale.h)
To determine the beginning and the end of a token, the function first scans from the starting location for the first
<cmath> (math.h)
character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this
<csetjmp> (setjmp.h)
beginning of the token for the first character contained in delimiters, which becomes the end of the token. The scan
<csignal> (signal.h)
also stops if the terminating null character is found.
<cstdarg> (stdarg.h)
<cstdbool> (stdbool.h) This end of the token is automatically replaced by a null-character, and the beginning of the token is returned by the
<cstddef> (stddef.h) function.
<cstdint> (stdint.h)
<cstdio> (stdio.h) Once the terminating null character of str is found in a call to strtok, all subsequent calls to this function (with a null
<cstdlib> (stdlib.h) pointer as the first argument) return a null pointer.
<cstring> (string.h)
<ctgmath> (tgmath.h) The point where the last token was found is kept internally by the function to be used on the next call (particular library
<ctime> (time.h) implementations are not required to avoid data races).
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h) Parameters
Containers:
str
Input/Output: C string to truncate.
Multi-threading: Notice that this string is modified by being broken into smaller strings (tokens).
Other: Alternativelly, a null pointer may be specified, in which case the function continues scanning where a previous
successful call to the function ended.
<cstring> (string.h)
functions: delimiters
memchr C string containing the delimiter characters.
memcmp These can be different from one call to another.
memcpy
memmove
memset Return Value
strcat
strchr
If a token is found, a pointer to the beginning of the token.
Otherwise, a null pointer.
strcmp
A null pointer is always returned when the end of the string (i.e., a null character) is reached in the string being
strcoll
scanned.
strcpy
strcspn
strerror Example
strlen
strncat 1 /* strtok example */
2 #include <stdio.h>
strncmp
3 #include <string.h>
strncpy
4
strpbrk 5 int main ()
strrchr 6 {
strspn 7 char str[] ="- This, a sample string.";
strstr 8 char * pch;
strtok 9 printf ("Splitting string \"%s\" into tokens:\n",str); Edit & Run
10 pch = strtok (str," ,.-");
strxfrm
11 while (pch != NULL)
types:
12 {
size_t 13 printf ("%s\n",pch);
macro constants: 14 pch = strtok (NULL, " ,.-");
NULL 15 }
16 return 0;
Discover more 17 }
Output:
See also
strcspn Get span until character in string (function )
strpbrk Locate characters in string (function )
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us
[try Beta version]
Search: Go
Not logged in
C++
Discover more Computer Science Programming Software
Information
Tutorials
Reference programming language C & C++
Articles
Forum
function
Reference memset <cstring>
C library:
void * memset ( void * ptr, int value, size_t num );
<cassert> (assert.h)
<cctype> (ctype.h) Fill block of memory
<cerrno> (errno.h) Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).
<cfenv> (fenv.h)
<cfloat> (float.h)
<cinttypes> (inttypes.h) Parameters
<ciso646> (iso646.h)
ptr
<climits> (limits.h)
Pointer to the block of memory to fill.
<clocale> (locale.h)
<cmath> (math.h) value
<csetjmp> (setjmp.h) Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char
<csignal> (signal.h) conversion of this value.
<cstdarg> (stdarg.h)
num
<cstdbool> (stdbool.h) Number of bytes to be set to the value.
<cstddef> (stddef.h) size_t is an unsigned integral type.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h) Return Value
<ctgmath> (tgmath.h) ptr is returned.
<ctime> (time.h)
<cuchar> (uchar.h)
<cwchar> (wchar.h) Example
<cwctype> (wctype.h)
1 /* memset example */
Containers:
2 #include <stdio.h>
Input/Output: 3 #include <string.h>
Multi-threading: 4
Other: 5 int main ()
6 { Edit & Run
<cstring> (string.h) 7 char str[] = "almost every programmer should know memset!";
functions: 8 memset (str,'-',6);
memchr 9 puts (str);
10 return 0;
memcmp
11 }
memcpy
memmove
memset
Output:
strcat
strchr
------ every programmer should know memset!
strcmp
strcoll
strcpy
strcspn See also
strerror memcpy Copy block of memory (function )
strlen
strncpy Copy characters from string (function )
strncat
strncmp memcmp Compare two blocks of memory (function )
strncpy
strpbrk
strrchr
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
C++
Discover more Software Computer Science Programming
Information
Tutorials
Reference programming language C & C++
Articles
Forum
function
Reference strerror <cstring>
C library:
char * strerror ( int errnum );
<cassert> (assert.h)
<cctype> (ctype.h) Get pointer to error message string
<cerrno> (errno.h) Interprets the value of errnum, generating a string with a message that describes the error condition as if set to errno
<cfenv> (fenv.h) by a function of the library.
<cfloat> (float.h)
<cinttypes> (inttypes.h) The returned pointer points to a statically allocated string, which shall not be modified by the program. Further calls to
<ciso646> (iso646.h) this function may overwrite its content (particular library implementations are not required to avoid data races).
<climits> (limits.h)
<clocale> (locale.h)
The error strings produced by strerror may be specific to each system and library implementation.
<cmath> (math.h)
<csetjmp> (setjmp.h)
Parameters
<csignal> (signal.h)
<cstdarg> (stdarg.h) errnum
<cstdbool> (stdbool.h) Error number.
<cstddef> (stddef.h)
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Return Value
<cstring> (string.h) A pointer to the error string describing error errnum.
<ctgmath> (tgmath.h)
<ctime> (time.h)
<cuchar> (uchar.h) Example
<cwchar> (wchar.h)
1 /* strerror example : error list */
<cwctype> (wctype.h) 2 #include <stdio.h>
Containers: 3 #include <string.h>
Input/Output: 4 #include <errno.h>
Multi-threading: 5
Other: 6 int main ()
7 { Edit & Run
<cstring> (string.h) 8 FILE * pFile;
9 pFile = fopen ("[Link]","r");
functions:
10 if (pFile == NULL)
memchr 11 printf ("Error opening file [Link]: %s\n",strerror(errno));
memcmp 12 return 0;
memcpy 13 }
memmove
memset
strcat Possible output:
strchr
strcmp Error opening file [Link]: No such file or directory
strcoll
strcpy
strcspn See also
strerror
strlen errno Last error number (macro )
strncat perror Print error message (function )
strncmp
strncpy
strpbrk
strrchr
strspn
strstr
strtok
strxfrm
types:
size_t
macro constants:
NULL
C++
Discover more Computer Science programming language Software
Information
Tutorials
Reference Programming
Articles
Forum
function
Reference strlen <cstring>
C library:
size_t strlen ( const char * str );
<cassert> (assert.h)
<cctype> (ctype.h) Get string length
<cerrno> (errno.h) Returns the length of the C string str.
<cfenv> (fenv.h)
<cfloat> (float.h) The length of a C string is determined by the terminating null-character: A C string is as long as the number of
<cinttypes> (inttypes.h) characters between the beginning of the string and the terminating null character (without including the terminating
<ciso646> (iso646.h) null character itself).
<climits> (limits.h)
<clocale> (locale.h)
This should not be confused with the size of the array that holds the string. For example:
<cmath> (math.h)
char mystr[100]="test string";
<csetjmp> (setjmp.h)
<csignal> (signal.h)
defines an array of characters with a size of 100 chars, but the C string with which mystr has been initialized has a
<cstdarg> (stdarg.h) length of only 11 characters. Therefore, while sizeof(mystr) evaluates to 100, strlen(mystr) returns 11.
<cstdbool> (stdbool.h)
<cstddef> (stddef.h) In C++, char_traits::length implements the same behavior.
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h) Parameters
<cstring> (string.h)
<ctgmath> (tgmath.h) str
<ctime> (time.h) C string.
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h) Return Value
Containers:
The length of string.
Input/Output:
Multi-threading:
Other:
Example
<cstring> (string.h) 1 /* strlen example */
functions: 2 #include <stdio.h>
memchr 3 #include <string.h>
memcmp 4
memcpy
5 int main ()
6 {
memmove Edit & Run
7 char szInput[256];
memset 8 printf ("Enter a sentence: ");
strcat 9 gets (szInput);
strchr 10 printf ("The sentence entered is %u characters long.\n",(unsigned)strlen(szInput));
strcmp 11 return 0;
strcoll 12 }
strcpy
strcspn
strerror Output:
strlen
strncat Enter sentence: just testing
strncmp The sentence entered is 12 characters long.
strncpy
strpbrk
strrchr See also
strspn strcmp Compare two strings (function )
strstr
strtok strchr Locate first occurrence of character in string (function )
strxfrm strrchr Locate last occurrence of character in string (function )
types:
size_t
macro constants:
NULL
Discover more
Home page | Privacy policy
© [Link], 2000-2022 - All rights reserved - v3.2
Spotted an error? contact us