赋值 null 中的不兼容类型

incompatible types in assignment null

当我尝试将名字和姓氏中的第一个字符设置为 null 并将其 return 设置为 1 时,我不断收到此错误。

我的代码是...

int DeregisterStudent(int SID, struct studentdata SRecord[])

{

        int index;

        index = SRecordSearch(SID, MAXRECS, SRecord);
        if(index >= 0)
        {
                SRecord[index].sid = 0;
                SRecord[index].lastname = '[=10=]';
                SRecord[index].firstname = '[=10=]';
                return 1;
        }
        return 0;
}

我得到的错误是 error:incompatible 输入赋值 对于这两行

 SRecord[index].lastname = '[=11=]';
 SRecord[index].firstname = '[=11=]';

你没有正确写入字符串,应该是

SRecord[index].lastname[0] = '[=10=]';

SRecord[index].lastname = "";

取决于 struct 的声明方式。在第二种情况下,您可能会覆盖动态分配的字符串指针,在这种情况下,它应该被 free()ed.