C language string operations related study notes

C language string operations related study notes

#include <string.h>
int strlen (char * str): returns the number of characters does not include the last '/ 0' of

  • The difference between the sizeof (char STR), it is only a non-operator function, returns the number two: 1.str [] is a static array, the length of which is occupied by the memory is returned. 2.str [] array is dynamic, it is returned '/ 0' the number of characters is turned off (including the '/ 0')

char * strcpy (char * dest, char * src): returns the first address of the desk ( easy to operate further on the target )

  • String copy operation, the parameter string src (including "/ 0") to the point where desk. It may cause overflow.

char * strncpy (char * dest, char * src, int num): returns the first address of the desk

  • A character string copy operation defined length, i.e. the front num src Desk copied to bits (0 if not filled with bits num)

char * strcat (char * dest, const char * src): returns the first address of the desk

  • After the end of the string after the string concatenation operator, the character string src to a splicing position desk '/ 0' and, at the same time '/ 0' splice moved.

char * strncat (char * dest, const char * src, size_t num): returns the first address of the desk

  • Defining a long string splicing operation, the n-bit strings together after the position src desk '/ 0' and to the.

int strcmp (const char * str1, const char * str2): returns the value 0 / <0 /> 0

  • String comparison operation, if the same is 0, s1> s2 returns, returns> value of 0; otherwise, return the value is <0.
    Analyzing two string size
    1) ASII yard) length
    if desired case-insensitive string comparison functions can be used stricmp

int strncmp(const char* str1,const char* str2,size_t num):同上

  • Defined length string comparison operation. (Compare the first n bits)

int atoi (char * s): returns the integer data after transformation or 0 (conversion failure)

  • The shaping operation is converted into a string of digital data, not by the ASCII code, but direct conversion
  • The header file is <stdlib.h>
  • supplementWith symmetrical function
  • Prototype: int itoa (int num, char * str, int jinzhi)
    function: Press the num decimal radix conversion, saving conversion results to get str points to memory.
    Returns: 0 if successful conversion, the conversion failed to -1.
Published 10 original articles · won praise 0 · Views 111

Guess you like

Origin blog.csdn.net/weixin_45076393/article/details/104478055