2015-04-05 100 views
-3

我不断收到这个错误,当我尝试在名字和姓氏来设置的第一个字符为空,并返回到一个1不兼容的类型赋值为null

我的代码是...

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

{ 

     int index; 

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

,我得到的错误是错误:不兼容的类型赋值为 这两条线

SRecord[index].lastname = '\0'; 
SRecord[index].firstname = '\0'; 

回答

0

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

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

SRecord[index].lastname = ""; 

取决于struct如何申报。在第二种情况下,您可能会覆盖动态分配的字符串指针,在这种情况下,它应该是free() ed。

+0

非常感谢!这工作。 – 2015-04-05 16:49:51