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

How to realize string rotation in C language

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how C language realizes string rotation". In daily operation, I believe many people have doubts about how C language realizes string rotation. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the question of "how C language realizes string rotation". Next, please follow the editor to study!

There are two ways to think about this topic:

1. The postposition of the first character and the forward push of the rest of the elements repeat this process K times (k is the number of left-handed characters).

Eg:

The string is "ABCDEF\ 0" and needs to be rotated by 2 characters

First save the first character to a variable, and then place all the remaining variables one bit earlier, that is, "BCDEF\ 0" (note here that the last Terminator\ 0 does not advance, leave a space).

Then give the variable used to save to the last position of the string (except\ 0), that is, "BCDEFA\ 0"

To do this process again is "CDEFGA\ 0"-"CDEFGAB\ 0"

Source code:

# include#include#includevoid Exchange (char * str, int k) {int iMagne; char temp; char * sta; for (I = 0; I < k; iSum +) {sta = str; temp = * str;// saves the first character for (m = 0; m

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