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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:39:06+00:00 2026-05-26T21:39:06+00:00

I am doing some basic file manipulations, and would like to store the name

  • 0

I am doing some basic file manipulations, and would like to store the name the file passed to an executable C program and create a new file that has an extension tacked on the original filename. For example, if this were what I typed on the command line:

a.out < some_file.txt

Where a.out is an executable, is there a way to get the string some_file.txt, so I could open up a new file and call it some_file.text.mod or something else?

argv[0] gets you a.out, and in scripting you could use $1 to access arguments (but not the filenames used in redirection), but neither of those is much use here.

Any ideas?

  • 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-26T21:39:06+00:00Added an answer on May 26, 2026 at 9:39 pm

    Sometime (and almost always in practice) /proc/self/fd/0 could be a symbolic link to the file. (But the symlink could be crappy, e.g. for a pipe, and this is Linux specific).

    So from inside your a.out you could call the readlink(2) system call on /proc/self/fd/0

    But doing that is a bit disgusting. However it works:

    % ls -l /proc/self/fd/0 < ~/.zshrc
    lr-x------ 1 basile basile 64 Nov  6 19:22 /proc/self/fd/0 -> /home/basile/.zshrc
    
    % date | ls -l /proc/self/fd/0
    lr-x------ 1 basile basile 64 Nov  6 19:23 /proc/self/fd/0 -> pipe:[599869]
    

    Again, it is highly Linux specific and not portable to other Posix systems.

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

Sidebar

Related Questions

After reading some posts like this one: Choose File Dialog It appears that Android
While doing some random experimentation with a factorial program in C, Python and Scheme.
While doing some refactoring I've found that I'm quite often using a pair or
There are obvious counterparts for some of file systems' basic operations (eg. ls and
I'm not sure what I am doing wrong here. I have some basic markup.
I have done some basic Perl coding but never something in python. I would
I'm writing a script that allows me to do some basic imposition within InDesign
While doing some basic validation on the ASP.Net (4.0) Request.Files (upload) collection I decided
I'm now doing some work with decoding MP3 files, but just have some basic
We are doing some embedded Linux project, the vendor provides us a basic filesystem

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.