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


ADVERTISEMENT

C :: Inserting String At Index In Linked List

Feb 17, 2013

I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linked list...

Code:
typedef struct node {
char* value;
struct node* next;
} LinkedList;
void llAddAtIndex(LinkedList** ll, char* value, int index) {

[Code] .....

View 6 Replies View Related

C++ ::  Find Duplicates Before Inserting Into Doubly Linked List

Mar 8, 2013

I have a text file that needs to be read by command line arguments. The text are all numbers and can have multiple numbers on one line separated by a space. I cannot use an array or sort the numbers.So say I have a text file, listNums.txt:

12
473 8 29
30 1
8
248 17 55
29 84
5

Basically I need to read one number, find out if its odd or even by dividing by 2, search the odd or even doubly linked list that it would go into to see if its in there, if its not then add it to the bottom of the list.

View 2 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++ :: 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 View Related

C++ ::  Reading Files Saved On Computer

Jul 20, 2014

I can't seem to get my program to read a file that's saved on my computer. Here's my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inputfile;
string name;

[Code] ....

View 6 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++ :: Library Program To Add Information About Books In Binary File

Jan 3, 2015

I am working on binary files in turbo c++ 3.5 and i want to create a library program. I want to add information about books in a binary file and do functions such as: Search and replace, delete a record, and etc.

I do this functions but i have 2 problems: 1. For example when i add 6 records about books to file, BooksReport function cant show all records and for example just show 4 or 5 records and when i search records, from 5 records, for example i just found 3 or 2 records. 2.When i search and replace a word on file, all records thats before this edited record, will be deleted.

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void add();
void search();
struct {
char name[20];

[Code]...

View 2 Replies View Related

C++ :: Editing Saved Records In A Text File?

May 19, 2012

i have this program that i am undertaking.....this project needs to store customer details, edit them and delete them...now i am facing the problem of deriving a code to edit those details...

MY CODE

HTML Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main () {
int choice [1];
string name;

[code].....

View 4 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/C++ :: Syntax For Inserting Strings Into A List Maintaining Alpha Order

Oct 10, 2012

Why the first code snippet inserts properly into a list and the second code snippet does not. The position of the bold expressions are the only differences. iter, s and LS were declared elsewhere in main().

snippet 1.)
while (true) {
    cout << "Enter string (ENTER to exit): ";
    getline(cin, s);
    if (s.size() == 0)

[Code] .....

View 2 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

C++ :: Doubly Linked List Header File?

Jul 7, 2013

I'm not sure why my destructor isn't working..

typedef struct Node;
struct Node {
char data;

[Code]....

View 4 Replies View Related

C :: Create Polymorphic Linked List Library File?

Sep 10, 2013

Linked lists seem to be the most erroneous and most frequent thing I use and post about nowadays. I've been wanting to handle data structures in my own library of functions, but I'm not sure how to imitate polymorphism without too many ambiguities. I could just pass some character or string value to represent a type, but I wanted to see if there was actually something more elegant I could use before I dive in.

View 4 Replies View Related

C++ :: Linked List Interface / Implementation And Driver File

Jun 12, 2013

I am having difficulty calling the constructor in interface portion of my program. I get the error: no matching function for call to ‘Node::Node(int, NULL)’ when I try to call it on line 26 within the main function.

code:
interface: [URL]
implementation: [URL]
main file: [URL]

View 7 Replies View Related







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