Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of string manipulation in C language

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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')

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report