?? 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