Introduction to C language ~ Strings and pointers ~

Character string by pointer

The character string by the pointer is declared and initialized as follows. char *p = "String";

Each of the pointer p and the string literal "String" occupy storage. Pointer p is the point that points to the first character of the string. By the way, the array name also refers to the first character.

Array of strings

char *p[] = {"C","JavaScript","swift"};

Library that handles strings

function function
strlen(s); Find the length of the string
strcpy(s1,s2); Copy the string from s2 to s1
strncpy(s1,s2,n); Set a limit on the number of characters that can be copied to strcpy
strcat(s1,s2); Concatenate strings
strncat(s1,s2,n); It is possible to set a limit on the number of characters that can be connected to strcat
strcmp(s1,s2); Find the magnitude relationship of character strings.Positive integer value if s1 is greater than s2,0 if equal,Negative integer if s2 is less than s1
atoi(nptr) The character string pointed to by nptr,Convert to int type representation.
atol(nptr) The character string pointed to by nptr,Convert to long type representation.
atof(nptr) The character string pointed to by nptr,Convert to double type representation.

Recommended Posts