473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read data to double linked list in C

4
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 6065
gpraghuram
1,275 Expert 1GB
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 Expert 100+
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
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
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(ifile, .... i don't know what's next?
May 15 '07 #5
CMoose
4
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 Expert 2GB
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
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,...
12
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...
4
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; }; ...
32
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
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()...
3
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...
1
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...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.