Linux Common C functions (memory and string operation 2) __oracle

Source: Internet
Author: User
Tags strcmp

strcat (connecting two strings)
Related functions
bcopy,memccpy,memcpy,strcpy,strncpy

Table header File
#include <string.h>

Defining functions
Char *strcat (char *dest,const char *src);

Function description
strcat () copies the parameter src string to the end of the string referred to by the parameter dest. The first argument dest to have enough space to hold the string to be copied.

return value
Returns the string start address of the parameter dest

Example
#include <string.h.>
Main ()
{
Char a[30]= "string (1)";
Char b[]= "string (2)";
printf ("Before strcat ():%s/n", a);
printf ("After strcat ():%s/n", strcat (a,b));
}

Perform
Before Strcat (): string (1)
After strcat (): String (1) string (2)
 

STRCHR (finds the first occurrence of the specified character in the string)
Related functions
Index,memchr,rinex,strbrk,strsep,strspn,strstr,strtok

Table header File
#include <string.h>

Defining functions
char * STRCHR (const char *s,int c);

Function description
STRCHR () is used to find the first parameter C address that appears in the parameter S string, and then returns the address where the character appears.

return value
If the specified character is found, the address of the character is returned, or 0 is returned.

Example
#include <string.h>
Main ()
{
Char *s=0123456789012345678901234567890 ";
Char *p;
P=STRCHR (S, ' 5 ');
printf ("%s/n", p);
}

Perform
5.68E+25
 

strcmp (comparison string)
Related functions
Bcmp,memcmp,strcasecmp,strncasecmp,strcoll

Table header File
#include <string.h>

Defining functions
int strcmp (const char *s1,const char *S2);

Function description
strcmp () is used to compare parameter S1 and S2 strings. The comparison of string sizes is based on the order of the ASCII code table, which is also the value of the character. strcmp () First S1 the first character value minus S2 First character value, if the difference is 0 then continue to compare the next character, if the difference is not 0 will return the difference value. For example, the string "Ac" and "ba" Comparisons return the Difference (-33) of the character "A" (65) and ' B ' (98).

return value
Returns 0 if the parameter S1 and the S2 string are the same. S1 returns a value greater than 0 if it is greater than S2. S1 returns a value less than 0 if it is less than S2.

Example
#include <string.h>
Main ()
{
Char *a= "ABcDeF";
Char *b= "AbCdEf";
Char *c= "Aacdef";
Char *d= "ABcDeF";
printf ("strcmp (a,b):%d/n", strcmp (a,b));
printf ("strcmp (a,c):%d/n", strcmp (A,c));
printf ("strcmp (a,d):%d/n", strcmp (a,d));
}

Perform
strcmp (a,b): 32
strcmp (a,c):-31
strcmp (a,d): 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.