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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:40:51+00:00 2026-06-03T10:40:51+00:00

Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17 `check.cpp: In function ‘int main()’:` check.cpp:14:55:

  • 0

Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17

`check.cpp: In function ‘int main()’:`

check.cpp:14:55: error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive]

/usr/include/getopt.h:152:12: error: initializing argument 2 of ‘int getopt(int, char* const*, const char*)’ [-fpermissive]

#include <iostream>
#include <cstring>
#include <string>
#ifdef USE_UNISTD
#include <unistd.h>
#else
#include "XGetopt.h"
#endif
using namespace std;

int main() {

string text="-f  input.gmn -output.jpg";
int argc=text.length();
cout<<"argc: "<<argc<<endl;
char const * argv = text.c_str();
cout<<"argv: "<<argv<<endl;
int c = getopt (argc, &argv, "f:s:o:pw:h:z:t:d:a:b:?");
cout<<"c: "<<c<<endl;
return 0;
}
  • 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-03T10:40:52+00:00Added an answer on June 3, 2026 at 10:40 am

    You are missing two things here:

    1. Argument list is not a string. It is a list of strings. Don’t get confused by shell or other programs that ask for a list of arguments as a single string. At the end of day, those programs would split a string into arrays of arguments and run an executable (see execv, for example).
    2. There is always an implicit first argument in argument list that is a program name.

    Here is your code, fixed:

    #include <string>
    #include <iostream>
    #include <unistd.h>
    
    int main()
    {
        const char *argv[] = { "ProgramNameHere",
                               "-f", "input.gmn", "-output.jpg" };
        int argc = sizeof(argv) / sizeof(argv[0]);
        std::cout << "argc: " << argc << std::endl;
        for (int i = 0; i < argc; ++i)
            std::cout << "argv: "<< argv[i] << std::endl;
        int c;
    
        while ((c = getopt(argc, (char **)argv, "f:s:o:pw:h:z:t:d:a:b:?")) != -1) {
            std::cout << "Option: " << (char)c;
            if (optarg)
                std::cout << ", argument: " << optarg;
            std::cout << '\n';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While validating my CSS on http://jigsaw.w3.org/css-validator/ I am getting following errors: 1.Property zoom doesn't
While i am trying to get value from arraylist,i got the following errors.My sample
Working on calling a C function from my asm project. I'm trying to push
Based on this: http://man7.org/tlpi/code/online/book/procexec/multi_wait.c.html int main(int argc, char *argv[]) { int numDead; /* Number
Possible Duplicate: Why can I only access static members from a static function? While
I have got many errors while installing shotdetect software. some errors were because of
Hi While I am trying to upload application it gives me this errors Please
I am gettings these type of errors in a MFC VS6 project while linking
I'm using the MessageBox class to show errors to users, and while that might
Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data

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.