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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:29:20+00:00 2026-05-31T00:29:20+00:00

I have a C code that creates an array of char pointers as the

  • 0

I have a C code that creates an array of char pointers as the following:

char* arr[100];

I use each element in this array to point to some string that is being calculated by another function. So basically arr[0] would point to string1 and arr[1] to string2, etc.

This works just fine. However I’m now asked to be more flexible by having the user to specify the number of strings as a parameter.

How can I do this with minimal changes to my code? I understand that I need to use malloc. However I’m getting a lot of warnings in all of the assignment statements I had before. I changed the declaration of the array as the following:

char* arr = (char*)malloc(n * sizeof(char*)); //where n is provided by user

I thought that I only needed to change the declaration. Now all of the assignment statements are giving warnings (“assignment makes integer from pointer without a cast”). The following is an example of an assignment statement:

arr[i] = str; //where str is defined as char* and is calculated by another function

Am I missing something here?

  • 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-31T00:29:21+00:00Added an answer on May 31, 2026 at 12:29 am

    If you’re looking to create an array of char *, you need a char **arr. Think of it as an array of char * — if you had an array of int, you would have int *. Since you have an array of char *s, you need char **.

    char** arr = malloc(n * sizeof(char*));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following code that creates a serverside object of the xmlhttp class.
I have some Javascript code that creates 2 arrays: One for Product Category and
So I'm running through a list of things and have code that creates an
I have some code that creates a new site in SharePoint. Upon browsing to
I have written code that automatically creates CSS sprites based on the IMG tags
I have some code that dynamically creates a new button through JavaScript that when
I have some javascript code that creates an img tag with a mouseover callback,
I have a bit of Javascript code that creates a save friendly version of
I have some code on my PHP powered site that creates a random hash

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.