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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:15:27+00:00 2026-06-09T20:15:27+00:00

I saw this source code in a book: #include <stdio.h> #include <unistd.h> int main(int

  • 0

I saw this source code in a book:

#include <stdio.h>
#include <unistd.h>


int main(int argc, char *argv[])
{
    char *delivery = "";
    int thick = 0;
    int count = 0;
    char ch;

    while ((ch = getopt(argc, argv, "d: t")) != EOF)
        switch(ch)
        {
            case 'd':
                delivery = optarg;
                break;

            case 't':
                thick = 1;
                break;

            default:
                fprintf(stderr, "Unknown option: '%s'\n", optarg);
                return 1;
        }

        argc -= optind;
        argv += optind;

        if (thick)
            puts("Thick Crust.");

        if (delivery[0])
            printf("To be deliverd %s\n", delivery);

        puts("Ingredients: ");

        for (count = 0; count < argc; count++)
            puts(argv[count]);

    return 0;
}

I can understand the entire source except:

argc -= optind;
argv += optind;

I know what is argc and argv, but what happen them in these two lines, what is “optind”
Explain me.

Thank you.

  • 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-09T20:15:29+00:00Added an answer on June 9, 2026 at 8:15 pm

    The getopt library provides several function to help parsing the command line arguments.

    When you call getopt it “eats” a variable number of arguments (depending on the type of command line option); the number of arguments “eaten” is indicated in the optind global variable.

    Your code adjusts argv and argc using optind to jump the arguments just consumed.

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

Sidebar

Related Questions

I was looking at the source code for ncmpcpp, and I saw this. #include
I just saw this code while studying the wordpress source code (PHP), You can
I saw the Qt source code like this: class Q_CORE_EXPORT QBasicAtomicInt { public: ...
Context I saw this in a source code. Question What is the JavaScript framework
I saw this piece of code in jQuery's source. I am a novice in
I saw this line in the jQuery.form.js source code: g && $.event.trigger(ajaxComplete, [xhr, s]);
in F# powerpack math provider source code: I saw this (in lapack_service_netlib.fs ) member
I was browsing the Django source code and I saw this function: def colorize(text='',
I saw this in some vb.net source code: Dim sTest As String = &
I recently saw this code being used in a source file in a C++

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.