473,386 Members | 1,798 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,386 software developers and data experts.

Storing data in a linked list

9
I am doing a program which parses/separates a list of facebook friends' comma-separated data then stores them into a linked list.

Lets say the list contains these: (format : First Name, Last Name, Birthdate, Gender, Status)

John,Doe,1/1/1990,m,I love burgers!
James,Dean,2/3/1867,m,I need some action!
Marilyn,Monroe,5/9/1825,f,I need some rest!

Then I have this structure

Expand|Select|Wrap|Line Numbers
  1. typedef struct _node_t {
  2.     Item iData;
  3.     struct _node_t *pNext;
  4. } node_t
where iData consists of

Expand|Select|Wrap|Line Numbers
  1. typedef struct {
  2.     char *first_name;
  3.     char *last_name;
  4.     char *birthdate;
  5.     char sex;
  6.     char *status
  7. } Item;
Then I have a working code for separating the data to first name, last name, etc
but I'm having a problem with storing them into the linked list. I get a segmentation fault everytime.

I'm supposed to have these ff functions:
Expand|Select|Wrap|Line Numbers
  1. node_t * createNode(Item iData) {
  2.     /*
  3.     Missing Code must:
  4.     Allocate new node
  5.     Set data member
  6.     Set next member
  7.      Return new node
  8.     */
  9. }
  10. void insertNode(node_t * pHead, Item iData)
  11. {
  12.        node_t *pNew;
  13.        node_t *pCur;
  14.  
  15.        pCur = pHead;
  16.        pNew = createNode(iData);
  17.  
  18.       /*
  19.        Missing Code must:
  20.        Insert the created node into a linked list
  21.       */
  22. }
such that in my main program

Expand|Select|Wrap|Line Numbers
  1. int main (void){
  2.  
  3.    node_t head;
  4.    head.pNext = NULL; 
  5.    //Other Variable Declarations
  6.    .
  7.    .
  8.    .
  9.    //PARSING CODE HERE
  10.    //After parsing and storing the parsed data into the structure Item
  11.    insertNode(&head, iData);
  12. }
  13.  

can you suggest some codes for the said functions??
Thanks in advance!
Mar 24 '10 #1
6 3044
Markus
6,050 Expert 4TB
Where do you get the segfault? Please post all of the relevant code.
Mar 31 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
Segmentation faults come when you try to access memory which you are not supposed to access. Debug using gdb and pin point the exact location.

Regards
Dheeraj Joshi
Apr 1 '10 #3
jkmyoung
2,057 Expert 2GB
? I don't really get the responses so far but:
Could you show us what you're doing in your missing code segments, eg what actual code are you trying where you have:
/*
Missing Code must:
Allocate new node
Set data member
Set next member
Return new node
*/

There's more than one way to do it, so it'd be best if we helped you out in a way that matches your coding style.
Apr 1 '10 #4
Frinavale
9,735 Expert Mod 8TB
From what I remember of segmentation faults is that sometimes it's hard to pin point where it occurs and why.

This can happen anywhere.
It could be happening when you are inserting the node into the list.
It could be happening when you are creating other nodes.
It could be happening when you are setting any member in the node....

If you are using development software that lets you step through your application you should start by doing that.

If you aren't then you may want to start writing output at various stages in your code to narrow down where you think the segmentation fault is happening...

Please remember that the segmentation fault may not actually be happening at the line where you stop at if you're print output...but it will give you a general idea...

-Frinny
Apr 1 '10 #5
Markus
6,050 Expert 4TB
jkmyoung, I don't see what's hard to understand about them. I ask for all of the relevant code. Dheeraj suggests that the user debug his application with something like gdb. Simples.
Apr 1 '10 #6
jkmyoung
2,057 Expert 2GB
Must have had too many tabs open at once. I think that line was supposed to be for a different forum question; sorry.
Apr 1 '10 #7

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

Similar topics

14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
1
by: Kay | last post by:
A linked list is storing several names. I want to make a queue if I input a name that is same as the linked list. How to make each node of a linked list storing a queue that are different with each...
3
by: DaveLessnau | last post by:
In a book on Data Structures that I'm reading, the authors are describing various linked lists and trees. In these, they start with some form of node class. What's driving me crazy is that they...
6
by: Shannan Casteel via AccessMonster.com | last post by:
I'll explain as well as possible...not an experienced user...but learning. I am working on a database for different kinds of problems with machines. A user will be able to select a problem...
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,...
2
by: Kay | last post by:
A linked list is storing several names. I want to make a queue if I input a name that is same as the linked list. How to make each node of a linked list storing a queue that are different with each...
3
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
3
by: blubzouf | last post by:
I am searching some info about accessing files with stdio functions. I am able to open a file, read in it with freaf, write in it with fwrite, modifying its data in "r+" mode ( without truncation...
0
by: tigerved | last post by:
I need to read a file which contains data like this .....there is a catch though ...Ill need to ignore the lines which contain balnk characters ....(i.e) blank space between two commas.... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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.