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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:02:43+00:00 2026-05-29T08:02:43+00:00

So, I am working on a Linux based command line utility, that has to

  • 0

So, I am working on a Linux based command line utility, that has to accept a few flags, and I have noticed some interesting behavior. I will be posting testing code that I was using outside of the main utility. I was using this code, so I did not have to alter the actual utility until I had working code that I could just insert. So here is the code that I have been fiddling with:

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

int main(int argc, char **argv) {
    while(--argc && (*++argv)[0] == '-') 
        putchar('*');

    printf("\n%s\n", argv[0]);
 }   

Please ignore the fact that all this program does is print an asterisk and print its own name when invoked with one argument -b. The printing of the asterik was just to show that the loop ran once. So, I run this in a terminal as “./test -n”, and I expected the output to be:

*./test

Much to my surprise, the output was:

*-b

I have a working theory of what the statement
(*++argv)[0] is doing, but I am still a little hazy on it. My assumption is that it steps across the array of pointers looking at the first character in each string pointed to, (*++argv)[0] is now dereferencing *argv[0] or element zero of the first argument string.

So, basically I have three questions:

  1. What exactly is that statement doing?
  2. Why can I not get back to argv[0] or argv[0][0], no matter what I try?
  3. Is storing the value at the address pointed to by argv[0] in another char *, this is the only way that I have been able to access that value at this point, the normal way around this?

I am really confounded by this at the moment and have tried everything that I can think of to work this out. At one point I had a loop that would print the alphabet, I don’t know what part of memory the program was accessing. The most interesting permutation was pulling sshid variables from somewhere.

Thank you all in advance for your help with this.

  • 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-29T08:02:44+00:00Added an answer on May 29, 2026 at 8:02 am

    ++argv changes argv to point to the next argument.

    Try something like

    int i = 0;
    while(--argc && argv[++i][0] == '-')
    

    Which maintains a separate index, instead of overwriting argv.

    Or

    char** argp = argv;
    while(--argc && (*++argp)[0] == '-')
    

    which works the same as the original, except it changes a copy of argv instead of the original.

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

Sidebar

Related Questions

I have a linux based web hosting provider (fatcow.com) that doesn't give any command
I have implemented some utility classes in Flex that I want to use in
In a Linux-based project that I am working on, I need to be able
I am working on building an embedded network appliance (linux based) and have come
Here's the information I have: I am working with a Linux based system using
I have a python-based daemon that provides a REST-like interface over HTTP to some
I'm working on a Linux based server system in which there are two network
I have a (from what I can tell) perfectly working Linux setup (Ubuntu 8.04)
Actually I have a file . I am working in linux environment. I need
I am working in the Linux environment, and I have a C++ program, what

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.