|
|
检测点8-18
1.假设数组a的内容是字符串“hello,world.”,编写一个程序将它反转为“.dlrow,olleh”,且不得借助于另一个数组进行。
参考答案:
# include <stdio.h>
int main (void)
{
char a [] = "hello world.", * p = a, * q = a;
while (* q != '\0') q ++;
q --;
while (p <= q)
{
char tmp = * p;
* p = * q;
* q = tmp;
p ++;
q --;
}
puts (a);
}
2.自己动手编写代码实现strcpy库函数的功能。
参考答案:
char * strcpy (char * restrict s1, const char * restrict s2)
{
char * r = s1;
while ((* s1 ++ = * s2 ++) != '\0') ;
return r;
}
|
|