C言語のコピー関数を実現し、コピーされた文字列を逆順にします.ライブラリ関数は使用できません.他の変数は定義できません.
1307 ワード
/*
C , , from 1234,
to 4321 void strcyp(char * to,const char * from) :
: 。
*/
#include <cstdio>
#include <cstdlib>
void strcyp(char *to, const char * from);
int main()
{
char *in = "asdf!1234+567!@#$%^&*()_+8*90?";
char *out;
int len = 1;
char *head;
head = in;
while (*head != '\0')
{
len++;
head++;
}
out = (char *)malloc(sizeof(char) * (len + 1));
strcyp(out, in);
head = in;
while (*head != '\0')
printf("%c", *head++);
printf("
");
head = out;
while (*head != '\0')
printf("%c", *head++);
printf("
");
delete out;
return 0;
}
void strcyp(char *to, const char * from)
{
/* */
if (from == NULL || *from == '\0'|| from == to)
return -1;
/* to from[0]*/
*to++ = *from++;
/* from , to -1*/
while (*from != '\0')
{
from++;
*to++ = -1;
}
from--;
*to-- = '\0';
/* from '-1' */
while (*to == -1)
to--;
while (*to != '\0')
*to++ = *from--;
}