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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:40+00:00 2026-06-18T11:32:40+00:00

I want to make this program do the printing in main() only there are

  • 0

I want to make this program do the printing in main() only there are no command line arguments.
If there are command line arguments (which should just be one integer), it should run the function bitcount().

How do I go about doing this? If there are no command line arguments I am not sure how this will work properly.

How would I check if the user put in a command line argument? And if they did, run bitCount() and not the main(). However if they do not put any command line integer argument, then it would just run main.

e.g ./bitCount 50 should call the bitCount function
but ./bitCount should just run the main

Here’s what I have so far:

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

int bitCount (unsigned int n);
int main ( int argc, char** argv) {

    printf(argv);
    int a=atoi(argv);

    //   int a = atoi(argv[1]);

    printf ("# 1-bits in base 2 representation of %u = %d, should be 0\n",
      0, bitCount (0));
    printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
      1, bitCount (1));
    printf ("# 1-bits in base 2 representation of %u = %d, should be 16\n",
      2863311530u, bitCount (2863311530u));
    printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
      536870912, bitCount (536870912));
    printf ("# 1-bits in base 2 representation of %u = %d, should be 32\n",
      4294967295u, bitCount (4294967295u));
    return 0;
  }

  int bitCount (unsigned int n) {
      //stuff here
  }
  • 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-18T11:32:41+00:00Added an answer on June 18, 2026 at 11:32 am

    argv is an array of strings that contains the program name followed by all arguments. argc is the size of the argv array. argc is always at least 1 for the program name.

    If there was a paramter argc will be > 1.

    So,

    if (argc > 1)
    {
        /* for simplicity ignore if more than one parameter passed, just use first */
        bitCount(atoi(argv[1]));
    }
    else
    {
        /* do stuff in main */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I want to make my program print out the date: 1/1/2009 But this
I don't want to make this into a which is better... MVC or WebForms
This program works well but I want to make this program tell the user
I'm writing a (legal) spy program. I want to make this program hidden on
I want to make this function work in my program, but Visual Studio tells
I have written this program that has a main function, inside which, I am
I want to make this hierarchy: <ul id=red class=treeview-red> <li><span>Item 1</span> <ul> <li><span>Item 1.0</span>
I want to make this form: echo '<form method=post action=ratinghandler.php style=width: 250px> <input type=hidden
I want to make this kind of query: create procedure something @name varchar(13) as
I want to make this 1332251639632 to this 1332251639 I try this code, but

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.