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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:32:52+00:00 2026-05-26T18:32:52+00:00

Do excuse me to the basicness of this question. I am at a loss

  • 0

Do excuse me to the basic”ness” of this question. I am at a loss with pointers at times. I have a char * but I need to convert it to a char * const * to be able to correctly use it in the fts() function. How do i do that?

Thanks

  • 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-26T18:32:53+00:00Added an answer on May 26, 2026 at 6:32 pm

    You are not supposed to do that kind of conversion, because the types are not compatible.

    About pointers and pointers to pointers

    char * is a pointer to a string of characters, whereas char ** is an pointer to a pointer to a string of characters. (the const is a bonus). This probably means that instead of supplying a string of characters, you should provide an array of string of characters.

    Those two things are clearly incompatible. Don’t mix them with a cast.

    About the fts_* API

    To find the solution to your problem, we need to read the fts_* function API (e.g. at http://linux.die.net/man/3/fts), I see that:

    FTS *fts_open(char * const *path_argv, int options,
              int (*compar)(const FTSENT **, const FTSENT **));
    

    with your char * const * parameter path_argv, the description explains:

    […] If the compar() argument is NULL, the directory traversal order is in the order listed in path_argv for the root paths […]

    which confirms that the fts_open function is really expected a collection of paths, not one only path.

    So I guess you need to pass to it something like the following:

    char *p[] = { "/my/path", "/my/other/path", "/another/path", NULL } ;
    

    About the const

    Types in C and C++ are read from right to left. So if you have:

    • char * : pointer to char
    • char const * : pointer to const char (i.e. you can’t modify the pointed string, but you can modify the pointer)
    • const char * : the same as char const *
    • char * const : const pointer to char (i.e. you can modify the pointed string, but you can’t modify the pointer)
    • char ** : pointer to pointer to char
    • char * const * : pointer to const pointer to char (i.e. you can modify the pointer, and you can modify the strings of char, but you can’t modify the intermediary pointer

    It can be confusing, but reading them in the right-to-left order will be clear once you are more familiar with pointers (and if you programming in C or C++, you want to become familiar with pointers).

    If we go back to the initial example (which sends a bunch of warnings on gcc with C99) :

    char ** p = { "/my/path", "/my/other/path", "/another/path", NULL } ;
    

    I played with the API, and you can feed it your paths two ways:

        char * p0 = "/my/path" ;
        char * p1 = "/my/other/path" ;
        char * p2 = "/another/path" ;
    
        /* with a fixed-size array */
        char * pp[] = {p0, p1, p2, NULL} ;
    
        FTS * fts_result = fts_open(pp, 0, NULL);
    

    Edit 2011-11-10: snogglethorpe rightfully commented this solution is not a C89 valid solution, even if it compiles successfully with gcc (excluding pendantic + C89 flags). See Error: initializer element is not computable at load time for more info on that

    or:

        /* with a malloc-ed array */
        char ** pp = malloc(4 * sizeof(char *)) ;
        pp[0] = p0 ;
        pp[1] = p1 ;
        pp[2] = p2 ;
        pp[3] = NULL ;
    
        FTS * fts_result2 = fts_open(pp, 0, NULL);
        free(pp) ;
    

    Edit

    After reading others answers, only two of them (mkb and moshbear) avoid the “just cast the data” error.

    In my own answer, I forgot the NULL terminator for the array (but then I don’t know the Linux API, nor the fts_* class of functions, so…)

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

Sidebar

Related Questions

Excuse what is probably a really basic question but how do I achieve this.
Excuse the beginner level of this question. I have the following simple code, but
Excuse me for not quite a programming question, but I need to burn a
Excuse me if this is a silly question but i'm a beginer here. I
Excuse the terrible question title. I have this PHP string and want to check
Excuse me if this is a sparse question but, I'm somehow confused wit the
Excuse the beginner question, but I'm having difficulty wrapping my head around this. Using
Please excuse me if this question is really obvious but i've tried everything. I
My question may appear really stupid for some of you but i have to
Excuse me for posting a similar question. Please consider this: date value 18/5/2010, 1

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.