What I'm trying to do is creating a structure array and pass it to a function. My function takes it as a pointer. But I'm having lots of errors which makes me mad. My deadline is approaching and still I've been trying to sort out what the problem is (for 4 hours now).

Here is my code:

typedef struct node{
	struct node *next;
	char *word;
	int wcnt;
}NODE;

typedef struct list{
	struct node *head;
	int counter;
}LIST;

void fillNode(LIST *lst[26]);
void createList(LIST *lst[26]);
NODE *createNode(char *word);
void insertEnd(LIST *lst[26], char *word, int num);

int main()
{
	LIST myList[26];
	lower();
	createList(&myList);
	fillNode(&myList);
}
Compiling...
main.c
C:\Users\Shadow Shooter\Projects\string1\odev\main.c(26) : warning C4047: 'function' : 'struct list ** ' differs in levels of indirection from 'struct list [26]'
C:\Users\Shadow Shooter\Projects\string1\odev\main.c(26) : warning C4024: 'createList' : different types for formal and actual parameter 1
C:\Users\Shadow Shooter\Projects\string1\odev\main.c(27) : warning C4047: 'function' : 'struct list ** ' differs in levels of indirection from 'struct list [26]'
C:\Users\Shadow Shooter\Projects\string1\odev\main.c(27) : warning C4024: 'fillNode' : different types for formal and actual parameter 1

main.obj - 0 error(s), 4 warning(s)

By the way, It's a linked list which should be passed as pointer.

Arrays are always passed as a pointer, so using &myArray seldom buys you anything.

Just use the array name when you call the function, and take a * out of your function prototypes and definitions.

Salem, could you please explain why we use * in function parameters for the following program. Isn't it the same situation?

int main()
{
	DLIST myList;
	createList(&myList);
.
.
}

void createList(DLIST *lst)
{
	lst->head=NULL;
	lst->tail=NULL;
	lst->count=0;
}

I've done what you told but the problem is changes made within a function is not applied after it returns back to main. Thus, I had wanted to use pointers to make changes permanent. Please HELP

Salem, could you please explain why we use * in function parameters for the following program. Isn't it the same situation?

I am not Salem, and I am sure he can explain it better than me, but meanwhile... createList(&myList); If not & you'll be passing the value of myList and
createList() would make a copy of it; any modification to the copy would not change the myList in main.
Now createList(DLIST *lst ) accepts a pointer to a structure as you know, that allows you to modify the value by reference and also it saves space by not making a copy of any structure of type DLIST.

With arrays: DLIST myList[26]; you wouldn't pass it to a function like you did before createList(&myList); you would call the function like createList( myList ); which is the same that saying createList( &myList[0] ); That is pointer to the first element of the array.

In which case:
The prototype of createList() could be void createList( DLIST *lst ) ; or void createList( DLIST lst[] ) ;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.