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 8335393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:39:58+00:00 2026-06-09T03:39:58+00:00

I would like to name output files based on a base filename with a

  • 0

I would like to name output files based on a base filename with a different extension. In C psuedo-code:

a_file = fopen(filename + ".dt1","wt");
b_file = fopen(filename + ".dt2","wt");
c_file = fopen(filename + ".dt3","wt");

I tried following this example using strncat, but my program keeps appending to filename.

f1=fopen(strcat(filename,".dt1"),"wt");
f2=fopen(strcat(filename,".dt2"),"wt");
f3=fopen(strcat(filename,".dt3"),"wt");

This outputs:

filename.dt1
filename.dt1.dt2
filename.dt1.dt2.dt3

I need the end result to look like:

filename.dt1
filename.dt2
filename.dt3
  • 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-06-09T03:39:59+00:00Added an answer on June 9, 2026 at 3:39 am

    Kind of a pain with standard C libs, but this is the way I would do it.

        char *fn = malloc(strlen(filename+5)); // Allocate a string with enough space
                                               // for the extensions.
    
        sprintf(fn, "%s.dt1", filename);       // Copy the name with extensions into fn.
        a_file = fopen(fn,"wt");               //
        sprintf(fn, "%s.dt2", filename);       //
        b_file = fopen(fn,"wt");               //
        sprintf(fn, "%s.dt3", filename);       //
        c_file = fopen(fn,"wt");               //
    
        free(fn); // Free the memory gained from malloc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to output the name of a variable, along
I would like to specify JNDI name for an EJB3 bean using annotation, but
I would like to get the name of a variable or parameter: For example
I would like to parse the folder name and file name from passed argument.
I would like to display the first and last name of the authenticated user.
I would like to be able to get the name of a variable as
I would like to show the system form name into the caption of the
I would like to know how the Cocoa Framework got its name. I know
I would like to be able to add a new SQL LOGIN and name
I would like to get the output of some command line argument (which I'm

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.