c++ - trying to compile stir library: error: invalid conversion from ‘const char*’ to ‘char*’ -


first, i'm pretty new c++ , c easy on me :-) second, know question has asked many times in many forms before, figure how bend answers case ...

i trying compile file called utilities.cxx stil library has kind of , "open source" license (not lgpl , don't know if can put here significant parts of it...

the code has following function in it:

char *replace_extension(char *file_in_directory_name,              const char * const extension) { char * location_of_dot =  strchr(find_filename(file_in_directory_name),'.'); // first truncate @ extension if (location_of_dot!= null) *(location_of_dot) = '\0';  strcat (file_in_directory_name,extension); return file_in_directory_name; } 

compiling gives error:

g++  -o3  -ffast-math -dndebug  -wall -wno-deprecated -i../lmf_v2.0 /includes -d_file_offset_bits=64  -i./include  -dstir_simple_bitmaps -dsc_xwindows  -o  opt/buildblock/utilities.o -mmd -mp -c buildblock/utilities.cxx  buildblock/utilities.cxx: in function ‘char* stir::replace_extension(char*, const  char*)’: buildblock/utilities.cxx:225: error: invalid conversion ‘const char*’ ‘char*’ make: *** [opt/buildblock/utilities.o] error 1 

any appreciated ... thanks,

oz

ok, first part answered ... here function causes second error:

const char * const  find_filename(const char * const filename_with_directory) { const char * name;  #if defined(__os_vax__) name = strrchr(filename_with_directory,']'); if (name==null) name = strrchr(filename_with_directory,':'); #elif defined(__os_win__) name = strrchr(filename_with_directory,'\\'); if (name==null) name = strrchr(filename_with_directory,'/'); if (name==null) name = strrchr(filename_with_directory,':'); #elif defined(__os_mac__) name = strrchr(filename_with_directory,':'); #else // defined(__os_unix__) name = strrchr(filename_with_directory,'/'); #endif  if (name!=null) // kt 10/01/2000 name++ changed name+1 return name+1; else return filename_with_directory; } 

this line causing error:

char * location_of_dot =      strchr(find_filename(file_in_directory_name),'.'); 

strchr() returns const char*, not char* when called const char* first argument (i'm assuming find_filename() returns const char *, otherwise wouldn't seeing error).

since want assign memory location returned strchr, don't want use overloaded version. change find_filename() return char*.

update: you've since posted code find_filename() , changing return type involve changing other stuff (and doesn't make sense besides). instead, cast either return value of find_filename() char* or cast result of strchr() char*.

example (uses const cast):

char * location_of_dot = const_cast<char*>(     strchr(find_filename(file_in_directory_name),'.')); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -