我收到此错误,但我不知道为什么
void mem_move(void* dest, void* src, unsigned size)
{
char* d = dest, * s = src;
char buff[100];
char* b = buff;
for (int i = 0; i < size; i++)
*b[i] = *s[i];
for (int i = 0; i < size; i++)
*d[i] = *b[i];
}
void main()
{
char buffer[] = "one two three ";
mem_move(buffer + 3, buffer, 10);
char buffer2[] = "one two three ";
mem_move(buffer2, buffer2 + 3, 10);
}
我应该提到我正在使用 Visual Studio Community Edition 2022
在这些陈述中
*b[i] = *s[i];
*d[i] = *b[i];
您使用下标运算符
[]
和解引用运算符 *
两次解引用指针。
写
b[i] = s[i];
和
d[i] = b[i];
注意,根据C标准,不带参数的函数main应该这样声明
int main( void )