我得到以下错误
在函数w_Endline中
/home/prog2/in_out.c:113:19: error: assignment of read-only l ocation ‘*(sent + (sizetype)(endlen * 1ul))’
sent[endlen]='\0';
/home/prog2/in_out.c: In function ‘w_White’:
/home/prog2/in_out.c:119:19: warning: initialization discards ‘const’ qualifier from pointer target type
char* endlen=sent+whitelen;
/home/prog2/in_out.c:120:6: warning: implicit declaration of function ‘isspace’ [-Wimplicit-function-declaration]
while(endlen>sent &&isspace(*endlen))文件
1.in_out.c http://ideone.com/nI15F4
void w_Endline(const char* sent)
{
size_t endlen=strlen(sent)-1;
if(sent[endlen]=='\n')
sent[endlen]='\0';
}
void w_White(const char* sent)
{
size_t whitelen=strlen(sent);
char* endlen=sent+whitelen;
while(endlen>sent &&isspace(*endlen))
{
endlen='\0';
--endlen;
}
}2.in_out.h http://ideone.com/lDxxhY
发布于 2015-03-04 16:03:59
不要在w_Endline中使用const,如果您正在修改指针,也需要isspace()函数的ctype.h头。同样,在w_White函数中,如果要分配const指针,则指针也必须是const。
char* endlen=sent+whitelen;应该是
const char* endlen=sent+whitelen;// because sent is const 实际上,const限定符意味着只读。
https://stackoverflow.com/questions/28858994
复制相似问题