RTKLIB reading

(1) strstr function

 

* strstr function

* Function: Find the position of the first occurrence of the string strTwo in the string strOne, excluding the terminator '\ 0';

* 用法:char *strstr(char *strOne, char *strTwo)


int main(int argc, const char * argv[]) {
    char strOne[] = "Hello A World";
    char strTwo[] = "A";   
    char *temp;    
    temp=strstr(strOne, strTwo);
    printf("temp=%s\n",temp);    
    return 0;
}

PS: The output is "A World"

(2)strrchr

原型:char *strrchr(const char *str, char c)

Function: Find the position of the last occurrence of a character c in another string str (from the right side of str to find the position of the first occurrence of the character c).

Return value: If the search character is found, the address at this position is returned (all characters from this position in the string to the end of the string are returned).
If the specified character cannot be found, the function returns NULL


void main(void)
{
    char sStr1[100];
    sStr1[0] = '\0';
    strcpy(sStr1,"Golden Global View");
    char *p = strrchr(sStr1,'i'); //从后往前查找'i'
    cout<<(p==NULL?"NULL":p)<<endl;

}

51686250uploading.4e448015.gifFailed to transfer and re-upload cancel PS: The output result is: iew

(3) strcmp
 trcmp function is the basic function in C / C ++, it compares two strings, and then returns the comparison result

The function form is as follows: int strcmp (const char * str1, const char * str2)
where str1 and str2 can be string constants or string variables, and the return value is integer. The returned results are as follows:
① str1 is less than str2, return a negative value or -1; 
② str1 is equal to str2, return 0;
③ str1 is greater than str2, return a positive value or 1;

The strcmp function actually compares the ASCII codes of characters. The principle of implementation is as follows: First, compare the first character of the two strings. If they are not equal, stop the comparison and get the result of the size comparison of the two ASCII codes; Then compare the second character and then the third character and so on. No matter what the two strings are, the strcmp function compares at most until one of the strings meets the ending character '/ 0', and the result can be obtained.

int main() {
    char dest[] = "Hello A World";
    char sour[] = "A";
    int  temp1;
    temp1 = strcmp(dest, sour);
    printf("temp=%d\n", temp1);
    return 0;
}
 PS: 输出结果为:1

 

strcpy function   
        strcpy function is used to achieve the copy of two strings. The general form is:  
                strcpy (1 in character, string 2)
        Among them, string 1 must be a string variable, not a string constant. The strcpy function completely copies the contents of string 2 to string 1, regardless of what was originally stored in string 1. After copying, the string 2 remains unchanged.  
Example:   Note that because the string is an array type, the copying of the two strings is not performed by the assignment operation.  
        t = s; / * wrong string copy * / strcpy (t, s); / * correct string copy * /
       

Published 2 original articles · liked 0 · visits 6

Guess you like

Origin blog.csdn.net/qq_31112171/article/details/105469579