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


ADVERTISEMENT

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++ :: 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/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++ :: 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/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++ :: Read Coordinates From Text File Into Double Linked List

Mar 25, 2014

I am doing c++ program to read coordinates from text file into double linked list. Everything seems to work perfectly but it stores only 298 items in linked list. Im not sure if my code is wrong or I missed something. On the debugger length of list is over a 1000 but like I said it print outs only 298.

View 2 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/C++ :: Linked List To Simulate Text Editor

Mar 10, 2015

I am trying to make a text editor in C++ that uses Linked Lists as the main driving force. I need to make a program that can add a line of text at a certain point, delete a certain line of text, print the entire text, and quit and save the text to the original text file inputted from the shell script. My problems are with the cpp file, and the linked list files. My remove function is not what I need it to be I know that. I also know that there are some problems with my cpp file myEditor. My code is below.

#include <sstream>
#include "linkylist.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[]) {
//node* head = new node;

[Code] ....

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

Visual C++ :: Doubly Linked List And Basic Text Editor

Sep 23, 2014

I'm supposed to make a basic text editor using a doubly linked list, I have pretty much written most of it but keep coming across several problems. In certain places,all marked in the code, I get the error "expected a declaration" ive looked online and nothing ive found works. And secondly I also get the error" declaration has no storage class or type specifier" but i havent been able to find anything that works either.

Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <assert.h>
#include <string>

[Code] ....

View 6 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++ :: 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 :: Reading From Text File

Mar 11, 2013

extracting records from a text file based on the user input of a specific date. Below is a image of the Text file with Dates and records that follow. a code to extract records from file based on the day the user enters with month and year not necessary here.so it is based on the day the user enters, which the code will extract the records and if day is not found then "DATE NOT FOUND"

View 12 Replies View Related

C :: Reading Text From A File

Mar 12, 2013

I'm writing a code which has to read a text from a file. In this text, there are some symbol and numbers (ex, This is $19 of....). Those symbols and numbers should be replaced with the words from the other file. i.e.

transformed file

This is just an $19 of what the $5 should obtain.

And $19 should be replaced from association file

19 example
5 program

The result:

This is just example of what the program should obtain. I'd like to save the first file content into an array of strings and the same for the text of second file.

View 2 Replies View Related

C++ :: Reading From A Text File

May 9, 2013

I got an assignment to do...and in that i need to get the inputs from a .txt file....and im not getting how to read the data i want and skip the rest thrash.

Lambton:

Name: chocolate
demand rate: 50
setup cost: 200
unit cost: 5.2
inventory cost: 2

[Code] ....

Program is about a coffee shop with two branches and i have to keep track of the stock in the stores.

Lambton and Callaghan are the stores.

How can i read them ? I know how to open the file to be read..

View 2 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 :: Reading Numbers From A Text File

Feb 23, 2013

The program runs fine but i just want it to read the inputs from a text file rather than user manually entering it! what changes should i make in the codes..

Code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
float friction,flow;

[Code] ....

View 4 Replies View Related

C++ :: Reading Matrices From Text File

Jan 2, 2014

I would like to program a simple finite element solver in c++ (I'm a relatively new programmer by the way). This is the issue, I have a text file with all the information of the model arranged in matrices; an input file would look something like this:

*nodes
1 0 0 0
2 10 15 0
3 17 2 0
4 -4 -1 0

*elements
1 1 2
2 2 3
3 3 4

*material
1 2.0e5 0.30 7.85e-9
2 7.0e4 0.21 2.11e-9

*loads
1 0 0 0
4 0 0 0

So, i want to read this text file and get each of the "*" matrices in its own array. The size of the matrices is not know.

View 1 Replies View Related







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