C++ :: Program Crashes When Reading Linked List From File?

May 5, 2013

Why program crashes when reading linked List from file?

#include <iostream>
#include <fstream>
using namespace std;
struct link{
int data;
link* next;

[Code] .....

View 4 Replies


ADVERTISEMENT

C :: Reversing Every K Nodes Of Linked List - Program Crashes While Running

Mar 11, 2013

The code below is for reversing every k nodes of the linked list. While running the Program it crashes.

Code:
#include<stdio.h>
#include<stdlib.h>
struct node {
int info;
struct node *next;

[Code] ....

View 1 Replies View Related

C :: Sorted Linked List - Crashes On Malloc

Sep 29, 2013

So I've been working on a sorted linked list homework assessment and I've been stuck on a problem for a while now. Below is my code for inserting a new object into the linked list, for some reason it keeps crashing whenever I try to malloc temp. (between the "checkpoint" and "after malloc" printf statements) .

Code:

int SLInsert(SortedListPtr list, void *newObj){
SortedListPtr curr = list;
SortedListPtr temp = NULL;
if(list->obj == NULL) /*if the list is empty insert obj into the first node*/ {
list->obj = newObj;
free(temp);

[Code] ....

View 13 Replies View Related

C++ :: Reading TXT File Into A Linked List

Nov 19, 2013

Code:
void loadData(fstream& fin, nodePtr head){
if (fin.eof()) {
return ;
}
else

[Code] .....

This is my function and it is not working.

View 7 Replies View Related

C++ :: Reading From A TXT File To A Linked List

Nov 17, 2013

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include "contacts.h"

using namespace std;

[Code] ....

Lines 29-32 I have a good feeling very wrong. Now I have never learned how to do this and my book covers nothing over this. I just took my final in C++ so this is not homework. I am trying to get better before Data Structures start next month.

View 3 Replies View Related

C :: Reading A Text File Into Linked List

Oct 15, 2013

I am trying to read in a text file and add strings from it word by word into a Linked List. I'm fairly new at C and don't quite understand pointers. I've had a few different errors just messing around with it, but now I'm getting an infinite loop within my main program.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct listNode { /* self-referential structure */
char data[50];
struct listNode *nextPtr;

[Code] ....

When I run my full code, it prints 12345ooooooooooooooooooooooo...etc. In my test file the first word is "Hello" so that's where the infinite 'o's come from. If the outer loop is the one that is infinite, then wouldn't the second while loop also execute more than once? What I mean is, why is the second print statement the only one that repeats itself?

View 5 Replies View Related

C/C++ :: Reading Data From File Into Linked List

Mar 26, 2015

I have a data file that looks like:

111111111
Lisa
Porter
3
ENEE 114
CMSC 412
ENME 515
333333333
Alex
Simpson
1
CMSC 412
***

In the form student ID and then first name last name number of courses and finally the course code(s). Im currently attempting to read these into linked lists with the following code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct CourseInfo {
int courseID;
char courseName[30];

[Code] ......

I get no errors or warnings however when i print this out i get:

111111111
Lisa

Lisa
Porter
3
ENEE 114
CMSC 412
ENME 515

And then the program crashes. So i know that for some reason the problem is the

fgets(rootPtr->FirstName, 22, p);

But I do not know why because it seems to work for the other fgets. I also want to know why the while loop never runs and it crashes instead.

View 14 Replies View Related

C/C++ :: Reading File From Text To Linked List

Dec 1, 2014

I have to initialize my stack (done by linked list) and I have a txt file for that. It looks like

123 Mike Smith 3.5 BA
124 John Weasly 2.9 CD

Here is what I have done so far:

However, I cannot reach any result.

Let me update:

123 Mike Smith 3.5 BA
124 John Weasly 2.9 CD

Here is what I have done so far:

struct Record{ //struct
float number;
char name[10];
char surname[10];
float GPA;
char mark[SIZE];
Record *next;
};

[Code]...

View 1 Replies View Related

C/C++ :: Reading Books Saved In DAT File And Inserting Them Into Linked List

Mar 13, 2015

I'm having a problem in my Library assignment, this section of my code is for reading in books saved in a 'book.dat' file on my desktop and inserting them into the linked list. It kind of works, but say if there is two books in the file, it only saves the second book twice.

eg in book.dat:
123 book1 Tolkien 2009 0
111 book2 Rowling 2009 0

So once these are read in, and I call my method displayAll(), it would display the second book twice..

void importFromFile(FILE *fp) {
struct book *aBook;
struct node *aNode;
aBook = (struct book *)malloc(sizeof(struct book));

[Code] .....

View 6 Replies View Related

C/C++ :: Program To Emulate Shopping List - File Not Reading Correctly

Jan 28, 2015

I have written an program to emulate a shopping list. Everything works fine, until I try to read in from a file. Here is my read and write code (the write code looks like it is working ok, but I figured I would include it just in case), and an example of what happens to a list that has been written, then read back in.

I took this list, and wrote it to a file, then read that file back in. The .txt file looks like everything was written out properly, but when I try to read that exact same list back in, this is what I get:

View 10 Replies View Related

C++ :: Reading Data To A Linked List

Mar 20, 2014

The input is in the following format

5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5

The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.

When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges). what I am doing incorrect?

// CSCI 3300

#include <cstdio>
using namespace std;
struct ListCell
{
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)

[Code]...

View 1 Replies View Related

C/C++ :: Dijkstra Algorithm - Reading In Data To A Linked List

Mar 20, 2014

Program to implement Dijkstra's Algorithm. Have Problems storing graph info into linked-list . The input is in the following format

5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5

The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.

When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges).

#include <cstdio>
using namespace std;
struct ListCell {
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)

[Code] ....

View 5 Replies View Related

C++ :: Linked List Search - Access Violation Reading Location 0xCCCCCCCC

Apr 12, 2014

I am getting an Unhandled exception at 0x00CB569E in AusitnHorton_Chapter17_7.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

And, It puts a little yellow arrow at this line:

cout << nodepointer->value << " ";//print current node

when I try to run this program.

//Program:Make a ListNode and simple linked list class. Test the linked list class by adding varous numbers to the list and then test for membership. Then include a search function that returns the position of x on the list, if not found return -1.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>
#include <fstream>
#include <cctype>
using namespace std;

class LinkedList

[Code] ....

View 3 Replies View Related

C :: Reading A File To Linked Lists?

Jun 20, 2013

I have to write a program that reads from a text file, which contains a list of stock hourly prices and the company names. Something like this:

78.52 82.56 75.10 71.97 Water Company
22.40 25.68 21.37 22.96 Mega Shipping Inc

Each company data will be kept in a structure that contains: a pointer for the name, an array of the prices, and the average price for the day. The structures will be kept in a linked list. Each node structure will contain a pointer to one company data, and a pointer to the next node structure.This is all I have so far..

Code:

typedef struct {
char *companyName;
double hourlyPrices[NUM_PRICES];
double avgPrice;
} COMPANYDATA;

}

[code]...

We have to sort the nodes alphabetically. My question is, how do I read the data from the file one line at a time, and insert them alphabetically one by one?

View 7 Replies View Related

Visual C++ :: Reading In Data And Displaying Out All Data In Linked List?

Feb 6, 2014

I am wanting to be able to add as many different instances of data, while the user has not stated 'n', but then it only ever writes back to the screen the input for the last set of data. Where as I want to display back to the screen all the data that has been entered.

Code:
#include <iostream>
#include <string>
/*Function Declaration*/
void createItem();
void returnItem();
//Items structure

[code]...

View 6 Replies View Related

C :: Linked List Program Not Recognizing A Function

Oct 22, 2014

I'm writing a linked list program for class that has a simple text based menu and I believe I am nearly done, it just wont recognize my "count" function as a function and I don't know why. The error comes up at line 70.

Code:

#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int datum;
struct node *next;
} node_t;

[code]....

View 3 Replies View Related

C :: Program To Manipulate Doubly Linked List

Nov 17, 2013

I'm trying to write a program that manipulates a doubly linked list. My professor wants it to have two structs, one called Node (containing the data, and pointers to the next and previous nodes) and one called DLList, which contains the nodes for the head and tail (which is then passed to all of my functions).

I'm a little confused how to access the head and tail, for instance, if I want to initially set them to null in the main function (he emphasized the need for this), or to use them in my functions. I've tried a lot of variations to call the head and tail, but I keep getting told that head and tail are undeclared in the function.

How might I access my head and tail, for instance in a main function, when they're defined like this? (I took out all of the logic in my functions for clarity)

View 1 Replies View Related

C++ :: Sort Function For Linked List Program?

Oct 7, 2013

I'm having trouble getting my sort function to work,

void Linkedlist::sort(int num)
{
node *q;
node *a;
int input=num;

[Code].....

I get a crash and I've narrowed it down to the last if statement. Also this function is meant to handle new members after 1 member has been added.

View 7 Replies View Related

C :: Sorting A Linked List - Program Abruptly Terminates?

Nov 29, 2014

I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:

Code: /*
* {
* SingleLinkedList.c
*
* Created on: 28-Nov-2014

[Code].....

View 3 Replies View Related

C :: Simple Program To Bubble Sort Values Of A Linked List

Nov 30, 2013

HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.

I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.

Code:

#include<stdio.h>#include<stdlib.h>
typedef struct node
{
int info;
struct node *link;

}Node, *NodePointer;
void printList (NodePointer head)
}

[code]...

View 4 Replies View Related

C/C++ :: Linked List Delete Function Freezing Program When Called

Aug 12, 2014

My program seems to be working fine, except for when I call on my delete function. I don't receive any errors, but when I call the delete function my program outputs nothing and freezes. As in, my print function (which is called before the delete function) doesn't even work. I've tried removing bits of the function to see if I could pinpoint where exactly the issue is, but I've had no luck.

#include <iostream>
#include <string>
using namespace std;
class List{
private:
struct node{
string _data;

[Code] ....

And the function that is causing me trouble:

void deleteNode(string data){
node* del = NULL;
t = h;
n = h;
while(n != NULL && n->_data != data){

[Code] .....

View 5 Replies View Related

C/C++ :: Linked List - Method To Add To File

Feb 21, 2013

I am trying to write a program which involves linked list. i have to create a method called add_aa( str ). I am reading from a text file. in the text file it just contains the values for str. what I am trying to do is create the method add_aa( str ) and add what corresponds to str from the file. here is what the output should look like. and what i have is very basic. here is what i have

inline void LList:: add_aa(const string _str) {
    cout << " p = " << std::hex << p << std::dec << '
'; 
}

I'm thinking using a for statement, but how to incorporate it

Attached Images : sample.JPG (35.2 KB)

View 1 Replies View Related

C# :: Reading A File To List Box

May 29, 2014

I am trying to open any selected textfile and have the text input be sent to a listbox... Originally I wrote this code for a textbox which worked great now that I am converting it to a listbox it doesnt seem to work so much. I left the default item names in order for better understanding of what is going on.

private void button1_Click(object sender, EventArgs e) {
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
label1.Text = openFileDialog1.FileName;
listBox1.Items.Add = File.ReadAllText(label1.Text);
}
}

View 5 Replies View Related

C :: Unable To Read TXT File Into A Linked List

Sep 15, 2014

I've been trying to read a .txt into a linked list in the attached code. I'm running into problems, specifically I'm getting errors on line 41 (curr->word=charTemp. I'm trying to set the word array equal to the charTemp array. I've tried strcpy with no luck .

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
//Struct for linked list
typedef struct node {
char word[25];
struct node *next;
} node;

[Code]...

View 2 Replies View Related

C++ :: Store Information From A File In Linked List

Aug 28, 2014

I'm trying to open a file (contains member information) and store the information in an object, which is then inserted into a linked list. However, the current code just leaves a blank command window hanging with nothing happening.

main.cpp - [URL] ....
MemberProf.h - [URL] ....
MemberProf.cpp - [URL] ....
LinkedList.h -[URL] ....

View 7 Replies View Related

C++ ::  Read From File And Insert Into Linked List

Feb 12, 2014

I have a program and function i'm having an issue understanding. Here is what it's doing in the main.

int main() {
orderedLinkedList<MemberDO> memberList;
MemberDO::readFromFile("Member.dat", memberList);
return 0;
}

So it is creating a linked list object using the MemberDO class type which has a int, string, char and double. Then it will call the readFromFile static function in the MemberDO. So this is where my problem is I have this function

void MemberDO::readFromFile(char *fname, orderedLinkedList<MemberDO>& list) {
}

How do I read in each individual data member from the input then create a new MemberDO object and insert the objects into the linked list specified in the second argument list?

Here is the MemberDO class declarations

class MemberDO {
private:
int key;
string lastName;
char firstInitial;
double dues;

[Code] ....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved