我收到语法错误“*”操作数必须是指针,但类型为“char”

问题描述 投票:0回答:1

我收到此错误,但我不知道为什么

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

c char syntax-error
1个回答
1
投票

在这些陈述中

*b[i] = *s[i];

*d[i] = *b[i];

您使用下标运算符

[]
和解引用运算符
*
两次解引用指针。

b[i] = s[i];

d[i] = b[i];

注意,根据C标准,不带参数的函数main应该这样声明

int main( void )
© www.soinside.com 2019 - 2024. All rights reserved.