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

  • Home
  • SEARCH
  • 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 7995013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:17:02+00:00 2026-06-04T14:17:02+00:00

I am trying to make a graph this program is just in initial phases

  • 0

I am trying to make a graph this program is just in initial phases where I
declared an array of structure pointers which holds address of vertices
*vertices[20] is an array which whose elements are all addresses of type struct node * which will contain the address of node of graphs.

#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node *links[10];
};
struct node *create_node(int);
void create_vertices(struct node **);
int main()
{
    struct node *vertices[20];
    int d, i, choice;
        *vertices[0]=(struct node *)malloc(sizeof(struct node)*20);
        create_vertices (&vertices);
}

struct node *create_node(int data)
{
    int i;
    struct node *temp = (struct node *)malloc(sizeof(struct node));
    temp->data = data;
    for (i = 0; i < 10; i++)
        temp->links[i] = NULL;
    return temp;
}

void create_vertices (struct node **v)
{
 int i,choice;
 i=0;
    printf("enter choice\n");
    scanf("%d", &choice);
    while (choice == 1) {
        printf("enter data\n");
        scanf("%d", &d);
        vertices[i] = create_node(d);
        i++;
        printf("enter choice\n");
        scanf("%d", &choice);
    }
}

Compiling the above code gives me following errors

bfs.c: In function ‘main’:
bfs.c:13:21: error: incompatible types when assigning to type ‘struct node’ from type ‘struct node *’
bfs.c:14:9: warning: passing argument 1 of ‘create_vertices’ from incompatible pointer type [enabled by default]
bfs.c:8:6: note: expected ‘struct node **’ but argument is of type ‘struct node * (*)[20]’
bfs.c: In function ‘create_vertices’:
bfs.c:35:16: error: ‘d’ undeclared (first use in this function)
bfs.c:35:16: note: each undeclared identifier is reported only once for each function it appears in
bfs.c:36:3: error: ‘vertices’ undeclared (first use in this function)

the program says an error in following line

    struct node *vertices[20];
*vertices[0]=(struct node *)malloc(sizeof(struct node)*20);

what is the harm in this kind of declaration.
I declare an array of pointers of type struct node * should I give memory also to them.

  • 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-04T14:17:03+00:00Added an answer on June 4, 2026 at 2:17 pm

    in main:

    create_vertices (&vertices);
    

    should be:

    create_vertices (vertices);
    

    Also: it would be more safe to let the create_vertices() function know what the size of the array is. The i index should not be allowed to exceed this size.

    UPDATE: in main, remove the line:

    *vertices[0]=(struct node *)malloc(sizeof(struct node)*20);
    

    Vertices[] is an array of 20 (uninitialised) pointers in automatic storage (“on the stack”).

    The create_vertices() function will give the pointers a value. (by calling malloc() and assigning the result to vertices[i])

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

Sidebar

Related Questions

I'm trying to make this logistic regression graph in ggplot2 . df <- structure(list(y
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying to make two lines appear in a graph according to this
I'm trying to create a 2D array to represent a weighted graph. To make
I'm trying to make a graph implementation for an assignment, which has Graph(GraphImp) objects
I'm trying to make a ggplot graph wich show the proportions of a variable
I'm trying to make a force directed graph using d3.layout.force , and I need
The graph I'm currently trying to make falls a little between two stools. I
trying to make a page which will recursively call a function until a limit

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.