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

The Archive Base Latest Questions

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

Right now, I have something like this… CMD console window: c:\users\username\Desktop> wrapfile.txt hello.txt Hello

  • 0

Right now, I have something like this…

CMD console window:
c:\users\username\Desktop> wrapfile.txt hello.txt

Hello

How would I get something like this?

CMD console window:
c:\users\username\Desktop> wrapfile.txt hello.txt hi.txt

Hello Hi

with this code?

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

int main(int argc[1], char *argv[1])
{
    FILE *fp; // declaring variable 
    fp = fopen(argv[1], "rb");
    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");
    }
}
  • 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:06:12+00:00Added an answer on June 15, 2026 at 1:06 pm

    Well, first of all: in your main declaration, you should use int main(int argc, char* argv[]) instead of what you have right now. Specifying an array size makes no sense when declaring an extern variable (that’s what argv and argc are). On the top of that, you are not using the correct types. argc is integer and argv is array of strings (which are arrays of chars). So argv is an array of arrays of chars.

    Then, simply use the argc counter to loop through the argv array. argv[0] is the name of the program, and argv[1] to argv[n] will be the arguments you pass to your program while executing it.

    Here is a good explanation on how this works: http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/#command-line

    My 2 cents.


    EDIT: Here is a commented version of the working program.

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char **argv)
    {
        FILE *fp;
        char c;
        if(argc < 3)    // Check that you can safely access to argv[0], argv[1] and argv[2].
        {               // If not, (i.e. if argc is 1 or 2), print usage on stderr.
            fprintf(stderr, "Usage: %s <file> <file>\n", argv[0]);
            return 1;   // Then exit.
        }
    
        fp = fopen(argv[1], "rb");   // Open the first file.
        if (fp == NULL)   // Check for errors.
        {
            printf("Error: cannot open file %s\n", argv[1]);
            return 1;
        }
    
        do   // Read it.
        {
            c = fgetc(fp); // scans the file
            if(c != -1)
                printf("%c", c);
        } while(c != -1);
        fclose(fp);   // Close it.
    
        fp = fopen(argv[2], "rb");   // Open the second file.
        if (fp == NULL)   // Check for errors.
        {
            printf("Error: cannot open file %s\n", argv[2]);
            return 1;
        }
    
        do   // Read it.
        {
            c = fgetc(fp); // scans the file
            if(c != -1)
                printf("%c", c);
        } while(c!=-1);
        fclose(fp);   // Close it.
    
        return 0;       // You use int main and not void main, so you MUST return a value.
    }
    

    I hope it helps.

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

Sidebar

Related Questions

Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
Right now I have something like this: <div id=pagebody> <div id=left-entries> </div> <div id=right-entries>
So right now I have an input validation method structured something like this: function
Right now I have something like this: <%= render :partial => widgets/type1.html.erb, :locals =>
So right now if I have something like this: //div[@class='artist']/p[x]/text() x can either be
Right now I have something like this.... Item.find({}, function (docs) { for (var i
Right now in some Java code I have something like this class A {
right now I have something like this for my s3.yml: development: bucket: mydev access_key_id:
In my code right now I have something like this: state.BytesRead += readPacket.Result; if
Simple question; right now I have something like this: typedef void(*MyFunctionPointer)(int); typedef std::vector <

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.