【发布时间】:2016-11-08 14:49:09
【问题描述】:
所以我正在艰难地学习 C (只是充实) - 但我遇到的一个额外问题是以下 -
#include <stdio.h>
char * mystrcpy(char *, char *);
int main(void) {
char dest[100];
char src[] = "Test string\n";
char *p;
if (p = mystrcpy(dest,src)) {
printf("%s\n",p);
return(0);
}
else {
printf("null pointer received\n");
return(1);
}
}
/* mystrcpy: Copy a string from s to a buffer pointer to by d.
d = destination buffer
s = source string
return value = a pointer to the beginning of the string in the
destination buffer.
*/
char * mystrcpy(char *d, char *s) {
}
我知道 *d 和 *s 都是指针变量,但我不确定这意味着什么,也不知道如何在这个问题的上下文中使用它们。任何帮助或“指针”(没有双关语)将不胜感激。
【问题讨论】:
-
不,不是
*d和*s是指针变量,而是d和s。区别很重要。 -
阅读有关字符串复制的文档en.cppreference.com/w/c/string/byte/memcpy
-
无论如何,您的书肯定会在提供您所描述的练习之前提供有关指针以及如何使用它们的材料。如果这些材料让您不确定如何进行练习,那么可能值得您花时间弄清楚文本的哪些方面似乎不清楚或不完整,并具体询问这些方面。
-
不要逃课!
-
谷歌“c指针教程”