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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:45:20+00:00 2026-06-01T10:45:20+00:00

While trying to take some arguments for C. I found it really difficult to

  • 0

While trying to take some arguments for C. I found it really difficult to get argv[] to work. I have:

int main(int argc, char *argv[])
{
  void updateNext();
  void fcfs();
  void spn();
  void srt();

  fp = fopen(argv[0],"r");
  op = fopen("output.dat","a+");

  if (strcmp(argv[1],"FCFS")!=0)
  {
    fcfs();
  }

  if (strcmp(argv[1],"SPN")!=0)
  {
    spn();
  }

  if (strcmp(argv[1],"SRT")!=0)
  {
    srt();
  }
}

I would like to enter something in a format of myprog input.data FCFS, but the above code gives me an error for “float point exception” the exception is gone after I hard code input.dat as a string in the program. Something wrong with argv[0] perhaps?

  • 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-01T10:45:21+00:00Added an answer on June 1, 2026 at 10:45 am

    In C, argv[0] is the name of your program (or more precisely, the first word the user typed on the command line to run your program, if run from a shell).

    So, avoiding argv[0] for your purposes, you’ll want to look at argv[1] for the file name and argv[2] for the other parameter.

    This would have been clear if you had used a debugger to trace through your program, or simply printed the value before you used it:

    printf("using file name %s\n", argv[0]);
    fp = fopen(argv[0],"r");
    

    It’s also a good idea to check that you have sufficient command line parameters by validating argc before accessing argv:

    if (argc < 3) {
        fprintf(stderr, "not enough command line parameters\n");
        exit(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Runnable implementation that does some work which might take some time
While trying to use LINQ to SQL I encountered several problems. I have table
I have been trying to display a MySQL table for some time and I
Sorry answer found while typing I am trying to connect to an external webservice
So I'm basically just trying to take in some file input, and then take
I am having troubles while trying to post some datas with one file (an
I have been trying to learn a bit more about delegates and lambdas while
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
While trying to answer a question in the vicinity ' Unit Testing WPF Bindings
While trying to connect to a database that's set to read only, the connection

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.