Common string operations in C

Source: Internet
Author: User

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
// # Include
      
        Int main (void) {char str1 [] = "This is the first string"; char str2 [] = "That is the other string"; // printf (strcpy (str1, str2); // copy string // printf (strncpy (str1, str2, 20); // copy string specified length content // printf ("% d ", strlen (str1); // String Length // printf (strcat (str1, str2); // link string // printf (strncat (str1, str2, 20 )); // specify the length of the link. // printf ("% d", strcmp (str1, str2 )); // compare the string size /// printf ("% d", strncmp (str1, str2, 5); // compare the string size with the specified length // char * pGot_char = Strchr (str1, 'I'); // returns the address of the character to be searched. // printf ("% c", * pGot_char ); // print the content of the address // if (strstr (str1, "the") = NULL) {// search for substrings // printf ("no found "); //} // else {// printf ("has found"); //} // char buf [40]; // gets (buf ); // read the input string into the array, which can contain spaces in the middle until the carriage return, different from scanf // printf ("% s", buf); // compared with gets, fgets can specify the maximum length of the input string // In addition, gets can only be used for the standard input stream stdin, and fgets can be used for any type of input string // when entering line breaks, fgets stores a '\ n' character, but gets does not. // Fgets (buf, sizeof (buf), stdin); // printf ("% s", buf); // convert the atof string to double, atoi string to int // atol string to long, atoll string to longlong // char value_str [] = "99.4"; // double value = atof (value_str ); // printf ("% f", value); // wide string // wchar_t proverb1 [] = L "This is a wide type string "; // wchar_t proverb2 [] = L "This is an other wide string"; // wchar_t wchar = L 'W'; // wchar_t wsring [] = L "wide "; // printf ("% S \ n", proverb1); // The print must use % S instead of % s. //// printf ("% d \ n", wcslen (proverb1); // width String Length, do not include the terminator '\ 0' // wcscpy (proverb1, proverb2); // copy the wide string // wcsncpy (proverb1, proverb2, 15 ); // copy the specified length // wcscat (proverb1, proverb2); // connection width string // wcscmp (proverb1, proverb2); // compare the size // wcsncmp (proverb1, proverb2, 15); // compare the width of a string of the specified length // wcschr (proverb1, wchar); // search for the width of the string // wcsstr (proverb1, wsring ); // search for the wide string wchar_t ina [80] = L "ss"; fgetws (ina, sizeof (ina), stdin); // obtain the input wide string, specifies the maximum length, and the standard input stream printf ("% S", ina); return 0 ;}
      
     
    
   
  
 

Related Article

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.