Basic summary of C language (iii)----------string summary

Source: Internet
Author: User

??    string processing function # # # <string.h>//string array header file//puts output function char str[20] = "ZYP"; printf ("Who Loves%s\n", str);    does not wrap puts (str); Puts ("GJ"); Unable to format output//gets input function
Char str2[15];
Gets (STR2); You cannot have spaces when using scanf, there can be spaces in the middle of gets
Puts (STR2); Strcat string Join function
Returns the address of the preceding string, saved in the preceding string array
strcat (str, str2);
Puts (str);
printf ("concatenated string is%s\n", str); strcpy string copy function//strcpy (STR1, str2) Copy string 2 into string 1, the contents of string 1 are overwritten str1 length >= str2 length STRCP Y (str, str2);
Puts (str); strcmp string comparison function
Char str3[] = "AC";
Char str4[] = "Fun";
printf ("%d\n", strcmp (STR3, STR4));   Strlen computes the length of the string char str5[] = "Demacia";  A Chinese character is utf-8 encoded by default, occupying 3 bytes of printf ("%lu\n", strlen (STR5)); ?? Capitalize the first letter of the word count the number of words//first define a string array
Char str[100];
Define the number of variable count statistics words
int count = 0;
int isword = 1; Used to judge whether words are
Input string
Gets (str);
The loop determines if the character is
for (int i = 0; Str[i]! = ' + '; i++) {
And judge if it's a word
if (str[i] = = ") {
Isword = 1; equals a space to indicate that this is the beginning of a word
}else if (Isword = = 1) {
Str[i] = str[i]-32;
count++;
Isword = 0; Loop to get a word and put Isword back to 0
}
} printf ("%d\n", count); Puts (str);

Basic summary of C language (iii)----------string summary

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.