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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:31:16+00:00 2026-05-12T10:31:16+00:00

This is a simple code that open and print the file content. #include <stdio.h>

  • 0

This is a simple code that open and print the file content.

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

int main  ( int arg_count, char *arg_vec[] ) {
    int ch;
    FILE * fp;
    int i;

    if (arg_count <2) {
        printf("Usage: %s filename\n", arg_vec[0]);
        exit(1);
    }

    if ((fp = fopen(arg_vec[1], "r")) == NULL) { // can't open file

        printf("Can't open %s \n", arg_vec[1]);
        exit(1);
    }

    for (i = 1; i <(arg_count+1); i++) {
         printf("%s \n\n", arg_vec[i]); // print file name

         while ((ch = getc(fp)) != EOF) {
             putc(ch,stdout); // print content
         }
    }

    fclose(fp);

    return 0;
}

But why it gives (null) at the end of it’s output printout:

Filename.txt

text
text
(null)
  • 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-12T10:31:16+00:00Added an answer on May 12, 2026 at 10:31 am

    You’re looping one to many times because of arg_count+1. The null is because you’re trying to print a filename that does not exist in the argument list. You also need to open and close for each file in your list.

    #include <stdio.h>
    #include <stdlib.h>
    
    int main  ( int arg_count, char *arg_vec[] ) {
        int ch;
        FILE * fp;
        int i;
    
        if (arg_count < 2) {
            printf("Usage: %s filename\n", arg_vec[0]);
            exit(1);
        }
    
        for (i = 1; i < arg_count; i++) {
             printf("File: %s \n\n", arg_vec[i]); // print file name
             if ((fp = fopen(arg_vec[i], "r")) == NULL) { // can't open file
                printf("Can't open %s \n", arg_vec[i]);
                exit(1);
             }
    
             while ((ch = getc(fp)) != EOF) {
                 putc(ch,stdout); // print content
             }
             fclose(fp);
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 190k
  • Answers 190k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would suggest using jQuery as it's probably one of… May 12, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer it looks like the problem has been talked about a… May 12, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer I think that it is called twice because the Height… May 12, 2026 at 6:00 pm

Related Questions

I was hacking away the source code for plink to make it compatible with
Is there a simple way to translate an XLS to a CSV formatted file
I'm working on a simple HTML scraper for Hulu in python 2.6 and am
I'm having a somewhat odd problem with Python(2.6.2) that I've come to the conclusion

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.