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

  • Home
  • SEARCH
  • 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 156901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:24:30+00:00 2026-05-11T10:24:30+00:00

I am using Linux GCC c99. I am wondering what would be the best

  • 0

I am using Linux GCC c99.

I am wondering what would be the best technique. To change a string. I am using strstr();

I have a filename called ‘file.vce’ and I want to change the extension to ‘file.wav’.

Is this the best method:

char file_name[80] = 'filename.vce'; char *new_file_name = NULL; new_file_name = strstr(file_name, 'vce'); strncpy(new_file_name, 'wav', 3); printf('new file name: %s\n', new_file_name); printf('file name: %s\n', file_name); 

Many thanks for any advice,


I have edited my answer using using your suggestions. Can you see anything else wrong?

/** Replace the file extension .vce with .wav */ void replace_file_extension(char *file_name) {     char *p_extension;      /** Find the extension .vce */     p_extension = strrchr(file_name, '.');     if(p_extension)     {         strcpy(++p_extension, 'wav');     }     else     {         /** Filename did not have the .vce extension */         /** Display debug information */     } }  int main(void) {     char filename[80] = 'filename.vce';      replace_file_extension(filename);      printf('filename: %s\n', filename);     return 0; } 
  • 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. 2026-05-11T10:24:31+00:00Added an answer on May 11, 2026 at 10:24 am

    I would do this

    char file_name[80] = 'filename.vce'; char *pExt;  pExt = strrchr(file_name, '.'); if( pExt )   strcpy(++pExt, 'wav'); else {  // hey no extension } printf('file name: %s\n', file_name); 

    You NEED to do pointer manipulation in every c program. Of course you’d do some more checking for buffer over runs etc. or even use the path specific functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

linux gcc 4.4.1 C99 I am just wondering is there any advantage using the
I'm fine working on Linux using gcc as my C compiler but would like
I am using gcc 4.4.2 on linux I am just wondering does gcc automatically
I have an Objective-C app build on Linux with GCC 4.3 using no specific
gcc 4.4.3 c89 linux I am using log4c and have placed the inc and
I would like to develop Adobe Flex applications using Linux and a free environment.
I have tried to find how to create DLL-s on linux using google, but
I am compiling my program that will run on linux gcc 4.4.1 C99. I
I am using make on linux. I downloaded the GCC source code from svn
I am trying to learn the shared library concepts on linux using GCC. So

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.