473,947 Members | 26,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read data to double linked list in C

4 New Member
I'm trying to write a program that reads data from a text file and stores it into a doubly linked list. I then want to be able to edit or sort the list.
However, I'm having trouble getting started with reading the file into a doubly linked list. Any advice would be appreciated. Thanks!!
May 15 '07 #1
6 6102
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
r u facing issues in reading a file or storing the value into the Linked list.
Have you written the linked list?
Please provide more info
Thanks
Raghuram
May 15 '07 #2
svlsr2000
181 Recognized Expert New Member
Simple write a program for doubly link list. I guess your node would look something like this

Expand|Select|Wrap|Line Numbers
  1. Struct Node{
  2.  
  3. struct Node * Next;
  4. struct Node * prev;
  5. int data
  6. };
When ever You create a new node just read the data from file using fscanf

Expand|Select|Wrap|Line Numbers
  1. fscanf(FilePtr,"%d", &(Node->data));
May 15 '07 #3
CMoose
4 New Member
This is what I have so far

Expand|Select|Wrap|Line Numbers
  1. #define GLEN 20
  2. #define TLEN 25
  3. #define RLEN 6
  4.  
  5. struct movie_s {
  6.  char title[TLEN];
  7.  char genre[GLEN];
  8.  char rating[RLEN];
  9.  unsigned short year;
  10.  unsigned short score;
  11.  struct movie_s *prev;
  12.  struct movie_s *next;
  13. };
  14. typedef struct movie_s movie_t;
  15.  
but now that I have that, I don't know what to do with it. How do I use this structure to edit the list? Where is the data from the text file being read into the list?
May 15 '07 #4
CMoose
4 New Member
This is what I have so far

Expand|Select|Wrap|Line Numbers
  1. #define GLEN 20
  2. #define TLEN 25
  3. #define RLEN 6
  4.  
  5. struct movie_s {
  6.  char title[TLEN];
  7.  char genre[GLEN];
  8.  char rating[RLEN];
  9.  unsigned short year;
  10.  unsigned short score;
  11.  struct movie_s *prev;
  12.  struct movie_s *next;
  13. };
  14. typedef struct movie_s movie_t;
  15.  
but now that I have that, I don't know what to do with it. How do I use this structure to edit the list? Where is the data from the text file being read into the list?
i was thinking that i could do a while loop to read the file until the end of the file, but how do i format a while loop with my structure?

while(fscanf(if ile, .... i don't know what's next?
May 15 '07 #5
CMoose
4 New Member
Expand|Select|Wrap|Line Numbers
  1. char *new_record (char *buffer) 
  2.  {
  3.     char *rec = (char *) malloc (GLEN+1);
  4.  
  5.     strcpy (rec, buffer);
  6.     return rec;
  7.  }

how do i call this function in main? or any similar function to edit the list?
May 15 '07 #6
Ganon11
3,652 Recognized Expert Specialist
You could write your own helper function. In your while loop, instead of calling fread or fscanf, call your helper function. This helper function can read into the title array, genre, rating, and other fields of a movie_s passed to it.
May 15 '07 #7

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

Similar topics

4
2482
by: Dan | last post by:
I'm trying to creat a data structure, that can be either a integer, double, string, or linked list. So I created the following, but don't know if it is the data structure itself causing problems, or something I am doing in the rest of the program. This is the data structure. struct node { char type;
12
15125
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition should be kept for references to previous element of list. Here is my solution below: struct node {
4
3618
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; };   struct pcb *pcb_pointer;
32
5973
by: Clunixchit | last post by:
How can i read lines of a file and place each line read in an array? for exemple; array=line1 array=line2 ...
6
2260
by: deanfamily | last post by:
I am re-posting my second problem. I have a double-linked list. I need to know if it is possible to remove just one of an item, instead of all that match the given criteria with the remove() command. Any thoughts?
3
3335
by: Little | last post by:
Could someone help me get started on this program or where to look to get information, I am not sure how to put things together. 1. Create 4 double linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier will be represented by a triple (I, length, string) where I is used to identify the type of
1
3344
by: Little | last post by:
Hello everyone. I am trying to do the following program and am unable to get the beginning portion to work correctly. The scanner works when I print the statements without the double linked list portion but I just need help with the beginning portion with the double linked lists. Here is the information needed to understand the code: Create 4 double linked lists as follows: (a) A double linked list called NAMES which will contain all...
4
4299
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event is stored in a double linked list, the whole list is sorted for the next round. My problem appears when subjecting the program to heavy load, that is, when I run the simulation for more than 10,000 miliseconds (every event occurs in...
2
19193
by: zl2k | last post by:
hi, I have one program runs fine on my i386 linux box but get the "glibc detected *** corrupted double-linked list" error on the x86_64 linux box. Please help me to figure out if it is my program's problem or the library's problem. The libraries I am using is the boost and stl. The original program is quite long and I shrink it short and still able to duplicate the error. Basically, I first create a priority queue and after several round...
0
10164
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
11173
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
11352
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
10694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9893
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
8256
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
6335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4540
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3544
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.