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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:31:48+00:00 2026-06-02T09:31:48+00:00

I have a 2d array of pointers (to strings) char *result[7000][14]; I want to

  • 0

I have a 2d array of pointers (to strings)

 char *result[7000][14];

I want to write a function that returns the first string in each “row”.

Here’s what I tried:

char *getRownames (int a, int b, char *matrix[a][b])
{
    char *rownames[a];
    for(int i=0;i<a;i++){
        rownames[i] = malloc(strlen(matrix[i][0])+1);
        strcpy(rownames[i],matrix[i][0]);
    }

    return *rownames;
}

And then

 char *names = getRownames(7000, 14, result);

I get an error that says conflicting types for getRowNames. Still getting used to C and having to allocate my own memory.

  • 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-02T09:31:50+00:00Added an answer on June 2, 2026 at 9:31 am

    You have a few things going on here.

    Function declarations/prototypes need to have fixed sizes for their arrays & matrices.*

    char *getRownames (int a, int b, char *matrix[a][b])

    won’t work because the compiler doesn’t know a or b when compiling your program. It would need to be

    char *getRownames (int a, int b, char *matrix[7000][14])

    if you know the array will be that size. Then you don’t need a or b at all. If you want to be able to pass matrices of varying sizes to the function, that’s a different matter entirely.

    *(Note the compiler allows you to leave out the first dimension of arrays: char *matrix[][14] or char *array[])

    Next, you’ll need to cast the return value from malloc to a char*, as malloc() returns void*:

    rownames[a] = (char*)malloc(strlen(matrix[i][0])+1);

    By the way, it should be rownames[i] in your loop. 🙂 Since i is your loop variable.

    And last, it looks like you want to return an array of char*, but return *rownames will send back just the first value in the array. Again, if you know the size the array will be, it’s easier to pass an existing array to the function and have it fill in the values. Otherwise you have to malloc the array to return.

    char *result[7000][14];
    char *firstRows[7000];
    //... other code that fills in these values
    getRownames(7000, 14, result, firstRows);
    
    void getRownames (int a, int b, char* matrix[7000][14], char* returnrows[7000])
    {
        for(int i=0;i<a;i++){
            returnrows[i] = (char*)malloc(strlen(matrix[i][0])+1);
            strcpy(returnrows[i],matrix[i][0]);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: std::vector<std::string> to char* array I have to call a c function that
What if i want to have an array of pointers to a function and
I have a C function that returns an unsigned char * that can either
I have a C code that creates an array of char pointers as the
I have C function that takes string pointer as a parameter. This functions returns
I have an array of strings defined like this: char** arrNames; Now I want
I have an array of char pointers of length 175,000. Each pointer points to
I have an array of pointers to a base class, so that I can
I have a structure that has an array of pointers. I would like to
Season's greetings! I have a function that prints out the contents of a char**

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.