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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:31:06+00:00 2026-06-04T17:31:06+00:00

I wish to have a file name as an argument to the C program.

  • 0

I wish to have a file name as an argument to the C program. I tried all the possible ways in fopen something like the below.

fp = fopen(*argv[2], "r");

Also used "*argv[2]" but did not work. I want to know where I am going wrong so that I can use this correctly. Thanks!

  • 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-04T17:31:08+00:00Added an answer on June 4, 2026 at 5:31 pm

    It should be

    fp = fopen(argv[2], "r");
    

    Please be aware that argv[0] will contain your exe name(with path), other arguments which you pass will start from argv[1].

    Refer to this for more details on using command line arguments in C.

    In your main function if you are getting char **argv as the argument, the array subscripting argv[1] automatically turns it into a char * which is expected as an argument by fopen.

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

Sidebar

Related Questions

I have a binary file I wish to read for my android app. the
I wish to execute a batch file and have it call itself 10 times.
I have a JSON file with a lot of unneeded data and I wish
I have various settings in my ccnet.config file and wish to pass them to
I have a header file like this: /* * APP 180-2 ALG-254/258/772 implementation *
I have this simple little batch file program that I wrote but it fails
I have a clj file using a certain namespace and I wish to define
I have a simple save file dialog that I wish to use as a
Good afternoon, I wish to have a script that will look for all files
I have an XML file loaded into a DOM document, I wish to iterate

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.