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!!
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
Simple write a program for doubly link list. I guess your node would look something like this - Struct Node{
-
-
struct Node * Next;
-
struct Node * prev;
-
int data
-
};
When ever You create a new node just read the data from file using fscanf - fscanf(FilePtr,"%d", &(Node->data));
This is what I have so far - #define GLEN 20
-
#define TLEN 25
-
#define RLEN 6
-
-
struct movie_s {
-
char title[TLEN];
-
char genre[GLEN];
-
char rating[RLEN];
-
unsigned short year;
-
unsigned short score;
-
struct movie_s *prev;
-
struct movie_s *next;
-
};
-
typedef struct movie_s movie_t;
-
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?
This is what I have so far - #define GLEN 20
-
#define TLEN 25
-
#define RLEN 6
-
-
struct movie_s {
-
char title[TLEN];
-
char genre[GLEN];
-
char rating[RLEN];
-
unsigned short year;
-
unsigned short score;
-
struct movie_s *prev;
-
struct movie_s *next;
-
};
-
typedef struct movie_s movie_t;
-
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?
- char *new_record (char *buffer)
-
{
-
char *rec = (char *) malloc (GLEN+1);
-
-
strcpy (rec, buffer);
-
return rec;
-
}
how do i call this function in main? or any similar function to edit the list?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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;
|
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 {
|
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;
|
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
...
|
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?
| |
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
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |