Thread: Don't understand how to fix this error

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    Angry Don't understand how to fix this error

    i keep getting this error
    next' : is not a member of 'book'

    here is the code any help would be great!!!!


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


    struct book
    {
    int code;
    char title[20];
    char author[20];
    int pages;
    }*head,*work,*next;

    main()
    {
    int code;
    char title;
    char author;
    int pages;
    int ans;
    struct book*head;*work;*next;
    head=(struct book*)malloc(sizeof(struct book));
    work=head;
    printf("Enter code:");
    scanf("%d",&code);
    printf("Enter Title:");
    scanf("%c", &title);
    printf("Enter Author:");
    scanf("%c", &author);
    printf("Enter Number of Pages:");
    scanf("%d",&pages);
    printf("Do you wnat to add another book?:1=yes/2=no");
    scanf("%s",&ans);
    while (ans!=1)
    {
    work->next=NULL;
    return 0;
    }
    work->next=(struct book*)malloc(sizeof(struct book));
    work=work->next;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    struct book
    {
    int code;
    char title[20];
    char author[20];
    int pages;
    }*head,*work,*next;
    Um, that's because 'next' is not a MEMBER OF 'book'. It is an INSTANCE OF. To elaborate:
    Code:
    struct book
    {
        struct book *next; //Now it's a member of.
    };
    A "member" of a structure must be INSIDE OF the struct. IE: It must fall between the opening and closing braces of its definition.

    Quzah.
    Last edited by quzah; 03-21-2002 at 07:29 PM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  4. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM