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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:48:06+00:00 2026-06-15T13:48:06+00:00

The title doesn’t really do this topic justice. It’s actually quite simple, my problem

  • 0

The title doesn’t really do this topic justice. It’s actually quite simple, my problem that is. I have a program (code below) written in the C language. I want this program to create an exe file that can be ran through the command prompt console window and that will also take a text file as a parameter. So, long story short; I need it to say this on the command line in CMD:

C:\Users\Username\Desktop\wrapfile.exe content.txt

My only problem is getting the code right. I want to tell Visual Studio: “The file you should open is given in the command prompt window as a parameter, there is no set location…”

How do I do that?

Here is my working code (Although you will have to change a few things in the *fp definition.

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{

    FILE *fp; // declaring variable 


    fp = fopen("c:\\users\\*Put you're PC username here*\\Desktop\\contents.txt", "rb"); // opens the file


    if (fp != NULL) // checks the return value from fopen
    {
        int i;
        do
        {
            i = fgetc(fp);     // scans the file 
            printf("%c",i);
            printf(" ");
        }
        while(i!=-1);
        fclose(fp);
    }
    else
    {
        printf("Error.\n");
    }
}

Thanks everyone!

  • 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-15T13:48:07+00:00Added an answer on June 15, 2026 at 1:48 pm

    As Ken said above, the arguments of the main method are the values that you pass in from the command line. Argc is ‘argument count’ and argv is ‘argument values’. So to open the fist argument passed in from the command line, change

    fp = fopen("c:\\users\\*Put you're PC username here*\\Desktop\\contents.txt", "rb"); // opens the file
    

    to

    fp = fopen(argv[1],"rb");
    

    Just make sure to do error checking (ie argv[1] is not null) before you try to fopen the input. Also FYI, in your case argv[0] will be the name of your executable.

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

Sidebar

Related Questions

The title doesn't actually fully describes the problem, that is: I have a table
I know that the title doesn't really say what I'm actually looking for, as
The title doesn't quite capture what I mean, and this may be a duplicate.
I'm sorry if this title doesn't describe the problem properly but I wasn't sure
My form doesn't have a title bar, so I am implementing the code to
I wanna check sharepoint title first and see if the lib doesn't have that
Ok I know the title doesn't really tell you what my problem is but
The title really really doesn't explain things. My situation is that I would like
I have the following code: <h2> <?php echo $this->item->title; ?> </h2> Dependent on the
The title doesn't give justice to the question. I have a site and I

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.