2015 Fufute write--string right

Source: Internet
Author: User

Two days ago I was in the rich blessing of the great blessing to participate in the preaching meeting. and took the written test, and finally, a big question, I'm here to talk about the solution, the meaning of these questions is this, you can only use the C library, implement a function void makestring (char *pstr,int N) (PS: Here, I now take the function name, what to remember is, Test), the function claims to be based on the ' pstr ' end of the string. The number of characters that need to be shifted to the right is N, implementing a similar input such as makestring ("Abcdefghi", 2), the string shifted right after the change: hiabcdeg;

The following gives me the solution at that time, I hope you crossing have any comments or suggestions to give me a lot of guidance.

void Makestring (char *pstr,int N)
{
Char buf_heart[20] = "";
Char buf_back[20] = "";
int iCount = 0;//total number of characters
int leave = 0;//The head does not move backwards
int i = 0;
char *p = PSTR;
while (*p! = ')
{
icount++;
p++;
}
if (n > ICount)
{
return;//exceeds string size returned
}
leave = icount-n;
for (i = 0;i < leave;i++)//The string to be placed at the end of the original string
{
Buf_back[i] = Pstr[i];
}
for (i = 0;i < icount;i++)//The string to which the original string was put to the head
{
Buf_heart[i] = Pstr[leave];
leave++;
}
strcpy (Pstr,buf_heart);
strcat (Pstr,buf_back);
}

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

2015 Fufute write--string right

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.