0

I get the following error

In function 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))

FILES

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

Ben
  • 10,056
  • 5
  • 41
  • 42
BDS
  • 97
  • 1
  • 1
  • 9

1 Answers1

0

Dont use const in w_Endline if you are modifying the pointer also you need ctype.h header for isspace() function. Also in w_White function if you are assigning a const pointer the pointer also needs to be const.

 char* endlen=sent+whitelen;

should be

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

Actually const qualifier means read-only

lychee
  • 1,771
  • 3
  • 21
  • 31
  • Well that has fixed the issue with in_out But i get error in other file name query.c 3.query.c http://ideone.com/uXzoLc 4.query.h http://ideone.com/umPmWO – BDS Mar 04 '15 at 16:29
  • query.c: In function ‘doQuery’: query.c:40:15: error: passing argument 1 of ‘w_Endline’ discards ‘const’ qualifi er from pointer target type [-Werror] w_Endline(title); ^ In file included from query.c:27:0: in_out.h:31:6: note: expected ‘char *’ but argument is of type ‘const char *’ void w_Endline(char* sent); ^ cc1: all warnings being treated as errors : recipe for target 'query.o' failed make: *** [query.o] Error 1 – BDS Mar 04 '15 at 16:31
  • @Adarshjaya12 modify in_out.h function prototypes (remove const) in w_Endline if you are going to modify arguments – lychee Mar 04 '15 at 16:47
  • It's hard exactly to tell whats going on from your dense compiler errors, if you still have errors ask another question – lychee Mar 04 '15 at 16:57