473,624 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not a structure or union error

2 New Member
hi there i am trying to build a linked list from read a file operation. this code only adds the first node to the list. the problem is i am facing with "error: request for member 'head' in something not a structure or union" error. here is the code;

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "PR-ADT.h"
  5.  
  6. void add_Node(LIST** , NODE*);
  7. LIST* create_list(void);
  8.  
  9. int main( void ) {
  10.  
  11.     LIST* list;
  12.     NODE* student;
  13.  
  14.     list = create_list();
  15.  
  16.     FILE* myfile;
  17.     char file_name[50];
  18.     char sentence[200];
  19.  
  20.     printf("Enter the name of the file you want to create your list: ");
  21.     gets(file_name);
  22.     printf("\n");
  23.  
  24.     myfile = fopen(file_name,"r");
  25.  
  26.     while ( myfile == NULL ) {
  27.  
  28.         printf("File cannot be opened!!! Enter a new filename: ");
  29.         gets(file_name);
  30.         printf("\n");
  31.  
  32.         myfile = fopen(file_name,"r" );
  33.     }
  34.  
  35.     while ( !feof(myfile) ) {
  36.  
  37.         fgets(sentence,200,myfile );
  38.         puts(sentence);
  39.     }
  40.  
  41.     rewind(myfile);
  42.  
  43.     student = (NODE*) malloc(sizeof(NODE));
  44.  
  45.     while ( !feof(myfile) ) {
  46.  
  47.         fscanf(myfile,"%s", &(student->first_name) );
  48.         fscanf(myfile,"%s", &(student->last_name) );
  49.         fscanf(myfile,"%s", &(student->email_addr) );
  50.         fscanf(myfile,"%d", &(student->phone_num) );
  51.         fscanf(myfile,"%s", &(student->address) );
  52.         fscanf(myfile,"%s", &(student->city) );
  53.         fscanf(myfile,"%d", &(student->zipcode) );
  54.  
  55.     }
  56.  
  57.     add_Node(&list,student);
  58.  
  59.     printf("%s", list->head->first_name );
  60.  
  61.     return 0;
  62. }
  63.  
  64. void add_Node(LIST** list, NODE* student) {
  65.  
  66.     NODE* new_stu = student;
  67.  
  68.     new_stu = (NODE*) malloc(sizeof(NODE));
  69.  
  70.     if( !new_stu ) {
  71.         printf("ERROR NOT ENOUGH MEMORY!!!\n");
  72.         return;
  73.     }
  74.  
  75.     else {
  76.  
  77.         new_stu->fn_next = NULL;
  78.  
  79.         if( *(list)->head == NULL ) {
  80.  
  81.             new_stu->fn_next = *(list)->head;
  82.             *(list)->head = new_stu;
  83.  
  84.             printf("Adding operation is succesfull\n");
  85.  
  86.             *(list)->count++;
  87.  
  88.             return;
  89.         }
  90.     }
  91.  
  92. }
  93.  
it gives the errors in add_Node function in all lines which include
Expand|Select|Wrap|Line Numbers
  1. *(list)
i try to add the first node only. so if i can manage to solve this problem i can continue on my work : ).
Apr 30 '11 #1
3 11395
Banfa
9,065 Recognized Expert Moderator Expert
Check your operator precedences, -> has a higher precedence than * and is applied first but list is not a pointer to a structure so the -> operator is not valid for it.

Using (list) does nothing and is a pointless waste of parentheses, you need to use parentheses to override the normal operator precedence by using (*list).
Apr 30 '11 #2
burak aktas
2 New Member
mate it worked. but i have a question this is my NODE and LIST structures;

Expand|Select|Wrap|Line Numbers
  1. typedef struct node {
  2.  
  3.     int birth_date;
  4.     int zipcode;
  5.     int phone_num;
  6.     char first_name[50];
  7.     char last_name[50];
  8.     char city[50];
  9.     char address[50];
  10.     char email_addr[50];
  11.  
  12.     struct node* fn_next;
  13.     struct node* ln_next;
  14.     struct node* birdat_next;
  15.  
  16. } NODE;
  17.  
  18. typedef struct {
  19.  
  20.     int count;
  21.     NODE* head;
  22.     NODE* tail;
  23.     NODE* current;
  24.  
  25. }LIST;
Expand|Select|Wrap|Line Numbers
  1. LIST* list
you say "list is not a pointer to a structure" . isn't this list includes 3 pointer to structures with names(head,tail ,current). could you explain why list is not pointer to a structure, i am confused : )_?
Apr 30 '11 #3
Banfa
9,065 Recognized Expert Moderator Expert
in add_node void add_Node(LIST** list, NODE* student) list is declared as LIST **. So list is not a pointer to a structure, it is a pointer to a pointer to a structure. To declare a pointer to a structure you would need LIST* list (not that that would be right for your code.

If list is a pointer to a pointer to a structure then it needs to be dereferenced twice to get a structure. Both * and -> dereference a pointer, but * dereferences any pointer and -> dereferences a pointer to a structure so you need the * to be applied first because *list is a pointer to a structure.
May 1 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
2761
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
10
11377
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
2
4024
by: SSM | last post by:
Hi, Does C standard comment about "Endianness" to be used to store a structure/union variables? Thanks & Regards, Mehta
8
3317
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. However, the DEBUG_EVENT structure is defined as a union, and the size and contents vary depending on the event code contained in the header. typedef struct _DEBUG_EVENT { DWORD dwDebugEventCode; DWORD dwProcessId;
3
2805
by: WaterWalk | last post by:
I read from c99 std TC2 community draft, and found the following statement in 6.7.2.3: "Tw o declarations of structure, union, or enumerated types which are in different scopes or use different tags declare distinct types. Each declaration of a structure, union, or enumerated type which does not include a tag declares a distinct type." Then consider this common practice. Struct A type is defined in a
84
15840
by: Peter Olcott | last post by:
Is there anyway of doing this besides making my own string from scratch? union AnyType { std::string String; double Number; };
1
1998
by: eshuv | last post by:
Hello.. I have a problem with the code (I have a .cpp and a header file in.cpp file Idefine the fuctions and in .h file the structure ,union and enumeration , ) when I compile the code it gives an error 'unexpected end of file '. plz tell me reason why it occures such error .
6
4096
by: npd1 | last post by:
what is the difference between structure & union
3
7711
by: SRK | last post by:
Hi, I wanted to use an anonymous union within an structure something like below - struct Test { union { std::string user; //char user; std::string role; //char role;
5
2947
by: msl24 | last post by:
Thanks in advance to anyone/everyone who can help. I've written a code (see below) that works for small test values of N and M, say N = 50 and M = 30. However, I run into problems when I try to use large values of N = 401450280 and M = 32768. I can compile the code, but when I run it, I get a "bus error" that appears to be caused by the malloc line in function help. See snippets below: struct coords{ float *length; }; void...
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.