What are the methods of string manipulation in C language
In this article, the editor introduces in detail "what are the string manipulation methods in C language", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what are the string manipulation methods in C language" can help you solve your doubts? let's follow the editor's way of thinking to learn new knowledge.
Strings are widely used in C language, because a lot of data processing is text, that is, strings, especially device interaction and web web interaction return almost all text data.
The string itself belongs to a character array, except that, unlike a character array, the string ends with'\ 0'. Because the string ends with'\ 0', it is convenient to calculate the length, copy, find, and stitch.
1. The definition of a string char buff [] = "I am a string"; char a [] = "1234567890"; char b [] = "abc"; char c [] = {'axiaqingzhongjia
Adding a\ 0 to the end of a normal character array becomes a string.
two。 Handle the case of letters in a string
Replace all uppercase letters in the string with lowercase letters. Or replace all lowercase letters with uppercase letters. It can be distinguished by formal parameters.
# include # include # include void func (char * str,int flag); int main () {char buff [100]; printf ("enter string from keyboard:"); scanf ("% s", buff); printf ("source string:% s\ n", buff); func (buff,0); printf ("convert lowercase:% s\ n", buff); func (buff,1) Printf ("lowercase to uppercase:% s\ n", buff); return 0;} / / function function: uppercase conversion / / flag=0 means uppercase conversion / / 1 means lowercase conversion to uppercase void func (char * str,int flag) {int data; while (* stringing letters'\ 0') {if (flag) {if (* str > = 'ajar & * str='A'&& * str')