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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:29:31+00:00 2026-06-10T17:29:31+00:00

I’m trying to pass a 2d-array (array of strings) to a function in C,

  • 0

I’m trying to pass a 2d-array (array of strings) to a function in C, but am running into an “incompatible pointer type” warning.

In function ‘main’:
warning: passing argument 1 of ‘addCodonstoHash’ from incompatible pointer type

Code follows below. I am trying to create a hash table using uthash that will have 3-letter strings as keys (representing DNA codons), and associated char values representing the amino acid that the codon is translated to. So in essence, from the below code, I would want a hash table of the form

{“GCT” : ‘A’, “GCC” : ‘A’, “GCA” : ‘A’, “GCG” : ‘A’, “GCN” : ‘A’}

where ‘A’ represents Alanine. But right now, I’m having trouble simply passing the array of codons to the function that should parse them and add them to the hash table. I’ve read through
Incompatible pointer type
and
Passing an array of strings as parameter to a function in C
to no avail… I thought I understood how arrays are allocated and degrade to pointers, but obviously not.

Furthermore, when I try to compute the length of the array in addCodonstoHash (there are going to be many differently-sized arrays representing the various amino acids), it’s returning 8 and 2, respectively, from the printf debug lines, and I can’t figure out why this is so. Can you guys steer me in the right direction?

/* Helper method for adding codons to hash table from initialized arrays */
void addCodonstoHash(char AAarray[][4], char AAname)
{   int i, size1, size;
    size1 = sizeof(AAarray);
    size  = size1 / sizeof(AAarray[0]);

    /* Debugging lines */
    printf("%d\n", size1);
    printf("%d\n\n",size);

    for (i = 0; i < (sizeof(AAarray) / sizeof(AAarray[0])); i++)
    {   add_codon(AAarray[i], AAname);
        printf(AAarray[i]);
        printf("\n");
    }
}


int main(int argc, char *argv[])
{   /*
     * Generate arrays for codons corresponding to each amino acid, will
     * all eventually be incorporated into hash table as keys, with AA
     * values.
     */
    const char Ala[][4] = {"GCT", "GCC", "GCA", "GCG", "GCN"};
    ...


    addCodonstoHash(Ala, 'A');

    delete_all(); 
    return 0;
}

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-06-10T17:29:32+00:00Added an answer on June 10, 2026 at 5:29 pm

    Ala has type const char(*)[4] (except when it is used as sizeof or & operand), but the parameter has type char(*)[4]. You need to declare this one as const.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.