Home >Common Problem >What header file is string.h?

What header file is string.h?

(*-*)浩
(*-*)浩Original
2019-06-03 15:35:5624311browse

string.h is a commonly used header file in the C language standard library, which is needed when using character arrays.

What header file is string.h?

string.h is widely used in both c language and c language, but the specific situations are not quite the same. Since traditional C was born out of C, the usage of this term in traditional C is similar to that in C language. In standard C, which has been modified and standardized by the American Standardization Organization, the definition is quite different.

The functions and differences between string and string.h in c

Answer: Generally in C libraries, for an old one, that is, with ".h" For library files with extensions (such as iostream.h), there is a corresponding one without the ".h" extension in the standard library after the new standard. In addition to the many improvements of the latter, there is another difference. The latter stuff is stuffed into the "std" namespace.

But only string is special.

Recommended course: C Language Tutorial.

The problem is that C needs to be compatible with the C standard library, and the C standard library happens to already have a header file named "string.h", which contains some commonly used C string processing functions.

This header file has nothing to do with C's string class, so is not an "upgraded version" of . They are two header files that have nothing to do with each other.

c What functions are included in ?

Answer: Commonly used functions are as follows:

strlen finds the length of a string

strcmp compares two strings to see if they are the same

strcat string connection Operation

strcpy string copy operation

strncat string connection operation (first n characters)

strncpy string copy operation (first n characters)

strchr query string

strstr Query substring function usage

The following is the detailed usage of the function in the string.h file, with additional examples:

strcpy

Function name: strcpy

Function: Copy one string to another

Usage: char *strcpy(char *destin, char *source);

Program example:

#include<stdio.h>
#include<string.h>
int main(void)
{
char string[10];
char*str1="abcdefghi";
strcpy(string,str1);
printf("%s\n",string);
return 0;

The above is the detailed content of What header file is string.h?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn