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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:46+00:00 2026-06-17T09:06:46+00:00

I more or less have an idea, but I’m not sure if I’ve even

  • 0

I more or less have an idea, but I’m not sure if I’ve even got the right idea and I was hoping maybe I was just missing something obvious. Basically, I have and array of strings (C strings, so basically an array of pointers to character arrays) like so:

char **words;

Which I don’t know how many words I’ll have in the end. As I parse the string, I want to be able to resize the array, add a pointer to the word, and move on to the next word then repeat.

The only way I can think of is to maybe start with a reasonable number and realloc every time I hit the end of the array, but I’m not entirely sure that works. Like I want to be able to access words[0], words[1], etc. If I had char **words[10] and called

realloc(words, n+4)  //assuming this is correct since pointers are 4 bytes

once I hit the end of the array, if I did words[11] = new word, is that even valid?

  • 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-17T09:06:47+00:00Added an answer on June 17, 2026 at 9:06 am

    Keep track of your array size:

    size_t arr_size = 10;
    

    And give it an initial chunk of memory:

    char **words = malloc( arr_size * sizeof(char*) );
    

    Once you have filled all positions, you may want to double the array size:

    size_t tailIdx = 0;
    
    while( ... ) {
        if( tailIdx >= arr_size ) {
            char **newWords;
            arr_size *= 2;
            newWords = realloc(words, arr_size * sizeof(char*) );
            if( newWords == NULL ) { some_error() };
            words = newWords;
        }
        words[tailIdx++] = get_next_word();
    }
    
    ...
    
    free(words);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no idea why, but my NSMutableArray 'items' will not take more than
I have code that looks more or less like the code below but it
Currently making a global volunteer site, and the webpages will more or less have
I have more or less been able to understand and implement all these concepts
I have some more or less linear data of the form: x = [0.1,
The title more or less says it all: I have a function which takes
I have a class that retrieves its memeber (more or less 10 members) from
I have the following code in a c++ listener class (more or less), which
For some time i have been making more or less little games. One level
I know that being open source does not necessarily makes a program more/less secure

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.