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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:42:22+00:00 2026-06-05T00:42:22+00:00

I am writing a program in which I have to pass an array of

  • 0

I am writing a program in which I have to pass an array of structure pointers to a function in main body as follows

     struct node *vertices[20];
create_vertices (&vertices,20);

implementation of function is some thing like this

void create_vertices (struct node *vertices[20],int index)
{
}

in this I have to pass an array of structure pointers with index 20,
the declaration I did outside mains is as follows I

void create_vertices(struct node **,int);

However each time compiling the code gives me problem in these three lines only as

bfs.c:26:6: error: conflicting types for ‘create_vertices’
bfs.c:8:6: note: previous declaration of ‘create_vertices’ was here
bfs.c: In function ‘create_vertices’:
bfs.c:36:15: error: incompatible types when assigning to type ‘struct node’ from type ‘struct node *’

I am unable to understand how should I be doing this.
What I want to be able to do is:

  1. Declare an array of structure pointers in main (which I already did).
  2. Pass the address of array to function (here is where I goofed up).
  3. Declare the correct prototype of function outside mains.

The code has to be on C and I am testing it on Linux.
Can some one point me?

  • 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-05T00:42:24+00:00Added an answer on June 5, 2026 at 12:42 am

    The type of &vertices in the call create_vertices(&vertices, 20) is not what you think.

    It is a pointer to an array of pointers to structs:

    struct node *(*)[20]
    

    and not

    struct node **
    

    Drop the & in the call and you’d be back in business.

    The compilation (using GCC 4.7.0 on Mac OS X 10.7.4):

    $ gcc -O3 -g -std=c99 -Wall -Wextra -Wmissing-prototypes -c x3.c
    x3.c: In function ‘func1’:
    x3.c:16:9: warning: passing argument 1 of ‘create_vertices’ from incompatible pointer type [enabled by default]
    x3.c:7:10: note: expected ‘struct node **’ but argument is of type ‘struct node * (*)[20]’
    $
    

    The code:

    struct node { void *data; void *next; };
    
    void make_node(struct node *item);
    void func1(void);
    void create_vertices(struct node **array, int arrsize);
    
    void create_vertices(struct node *vertices[20], int index)
    {
        for (int i = 0; i < index; i++)
            make_node(vertices[i]);
    }
    
    void func1(void)
    {
        struct node *vertices[20];
        create_vertices(&vertices, 20);
    }
    

    Drop the & and the code compiles cleanly.

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

Sidebar

Related Questions

i have written a c program to which i pass in a script like
I have been writing a program which asks you to input two integers, which
I was writing a command line program which will have a status bar, much
I am writing a program which will preform texture synthesis. I have been away
I am writing a small C++ program which passes a 2-D array (of complex
I'm writing a program in python which should be able to pass callables which
I'm writing a program which has both an ASP.NET configuration system and a Silverlight
I am writing a program which if I compile on a Suse 10 32-bit
I'm writing a program which will use scan conversion on triangles to fill in
I'm writing a program which will allow to load a specific managed .DLL file

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.