On Fri, 4 Jan 2013 18:14:46 -0600 (CST),
galo...@gmail.com wrote:
>Any help here would be GREATLY appreciated! Thanks!!!
>
>Here is my compiler response:
>
>"gcc "./Desktop/C Programs/HeadFirstTests.c" -o "./Desktop/C Programs/HFT" && "./Desktop/C Programs/HFT"
>./Desktop/C Programs/HeadFirstTests.c: In function �addFirst�:
>./Desktop/C Programs/HeadFirstTests.c:40:16: warning: assignment from incompatible pointer type [enabled by default]
>./Desktop/C Programs/HeadFirstTests.c: In function �printList�:
>./Desktop/C Programs/HeadFirstTests.c:51:7: warning: assignment from incompatible pointer type [enabled by default]
>"
>
>
>/* This program builds
> a basic linked list.
> gcc "./Desktop/C Programs/HeadFirstTests.c" -o "./Desktop/C Programs/HFT" && "./Desktop/C Programs/HFT"
>*/
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>
>typedef struct { // Define a linked list node
At this point, you have "forward declared" a tagless structure type.
> char *name;
> struct LLNODE *next;
At this point, you have "forward declared" a structure type called
struct LLNODE.
>}LLNODE;
At this point, you have finished the definition of the tagless
structure and created a type LLNODE that is an alias for this
structure. Note that LLNODE is a completely different type than
struct LLNODE.
>
>
>void addFirst(char *data); //Declare function prototypes
>void printList(void);
>
>LLNODE *head = NULL; //Defind global pointer variable head
>
>
>int main(int argc, char *argv[])
>{
>
> addFirst("Johnson");
> addFirst("Robert");
> addFirst("Jerimiah");
> printList();
>
>
> return EXIT_SUCCESS;
>}
>
>void addFirst(char *data)
>{
>
> LLNODE *newNode;
> newNode = malloc(sizeof(LLNODE));
> newNode->name = data;
> newNode->next = head; //Keep getting errors here.
next is a pointer to struct LLNODE. head is a pointer to LLNODE. As
noted above, the two are not the same or even compatible types.
> head = newNode;
>
>}
The solution to your problem is to add the tag LLNODE to you tagless
structure so that LLNODE and struct LLNODE refer to the same type.
--
Remove del for email