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