Unix网络编程/套接字编程

时间:2015-03-04 15:58:34

标签: unix-socket

我收到以下错误

在功能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

1 个答案:

答案 0 :(得分:0)

如果要修改指针,请不要在w_Endline中使用const,ctype.h函数需要isspace()标头。同样在w_White函数中,如果要分配const指针,则指针也需要为const。

 char* endlen=sent+whitelen;

应该是

const char* endlen=sent+whitelen;// because sent is const 

实际上const限定符意味着只读