Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3456998
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:48:23+00:00 2026-05-18T09:48:23+00:00

First, I’m pretty new to C++ and C so be easy on me :-)

  • 0

First, I’m pretty new to C++ and C so be easy on me 🙂
Second, I know this question has be asked many times in many forms before, but I could figure
how to bend the answers to my case …

I am trying to compile a file called utilities.cxx from the STIL library which has some kind of and “open source” license (not really LGPL and so I don’t know if I can put here significant parts of it…

The code has the 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 at extension
if (location_of_dot!= NULL)
*(location_of_dot) = '\0';

strcat (file_in_directory_name,extension);
return file_in_directory_name;
}

Compiling it gives the 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 from ‘const char*’ to ‘char*’
make: *** [opt/buildblock/utilities.o] Error 1

Any help would be appreciated … Thanks,

Oz

Ok, first part already answered … here is the function which causes the 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 to name+1
return name+1;
else
return filename_with_directory;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:48:24+00:00Added an answer on May 18, 2026 at 9:48 am

    This line is causing the error:

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

    strchr() returns a const char*, not a char* when called with a const char* as the first argument (I’m assuming find_filename() returns a const char *, otherwise you wouldn’t be seeing this error).

    Since you want to assign to the memory location returned by strchr, you don’t want to use this overloaded version. Change find_filename() to return a char*.

    UPDATE: You’ve since posted the code for find_filename() and changing the return type would involve changing other stuff (and doesn’t make much sense besides). Instead, cast either the return value of find_filename() to a char* or cast the result of strchr() to a char*.

    Example (uses a const cast):

    char * location_of_dot = const_cast<char*>(
        strchr(find_filename(file_in_directory_name),'.'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I know this may be a very stupid question, so don't shoot
First, I'm not a regex expert, so I'm pretty sure I'm doing something wrong.
First of all: this is not a homework assignment, it's for a hobby project
First of all, I am new to the Silverlight + MVVM world. So I
First of all I have seen that there are many questions about unrecognized selector
First, please tell me if I'm not allowed to ask about this protocol here...
first a little bit of documentation from the jQuery validation plugin: Use submitHandler to
first post here so sorry for the length of it. I've been lurking and
First of all, sorry for the title. Someone please propose a better one, I
First off, I'm not really sure how much information is necessary to include because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.