Graph adjacency list representation
===

I am trying to write a basic graph program in c. However, an error message displays saying that the `The arrayOfVertices is undeclared`. I am using adjacency list representation and the code is


----------

    #include <stdio.h>
    #include <stdlib.h>

    struct graphnode
    {
    int name;
    struct graphnode *next;
    };

    void addNode(struct graphnode *G[],int startNode, int endNode)
    {
    // creating a new linked list which is to be added
    struct graphnode *tmp;
    tmp->name=endNode;
    tmp->next=G[startNode];
    startNode=tmp;
    }

    void printGraph(struct graphnode *G[], int numofnodes)
    {
    int i;
    for(i=0;i<numofnodes;i++)
    {
        struct graphnode *tmp;
        tmp=G[i];
        printf("%d",i);

        while(tmp!=NULL)
        {
            printf("%d",tmp->name);
            tmp=tmp->next;
        }
    }
    }

    int main(void)
    {
    int numofnodes;
    printf("Enter the number of nodes: ");
    scanf("%d",&numofnodes);

    // Note that we have created depending upon the size inputted by the user
    struct graphnode *arrayOfVertices[numofnodes];
    int i;      // for iteration

    for(i=0;i<numofnodes;i++)
    {
        arrayOfVertices[i]->name=i;
        arrayOfVertices[i]->next=NULL;
    }

    addNode(arrayOfVertices,0,1);
    addNode(aarrayOfVertices,0,2);
    printGraph(arrayOfVertices,numofnodes);
    
    return 0;
    }


----------
My approach is to create an array (of struct graphnode type) containing as many nodes as entered by the user. The structure contains two fields, one containing the number and the other containing pointers.


----------

 

 