C/C++ :: Loading Data From Text File Into Array

Jan 25, 2015

I am currently working on a project that requires me to "load the data in the file into array at the beginning of the program."

I have a text file with data, and I need to populate an array with the information. From then on, I am supposed to be able to add, display, and search that array. However, I can't figure out how to add the data from the file into an array. I was trying to find out how to search the text file itself. So it threw me off balance and I've been staring so long at the screen I can't really focus.

View 7 Replies


ADVERTISEMENT

C++ :: Pointer-based Data Loading From A (text) File

Dec 4, 2013

I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:

class buyerListType
{
public:
setCustomerInfo( ....., productListType* p);
.
.
.
private:
productListType* productBoughtRecord;
.
.
};

I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.

View 11 Replies View Related

C :: Loading Text File To Array

Jul 19, 2013

I'm having troubles with loading my text file into my array.

Code:

int main(int argc,char* argv[]) {
if(argc!=3) {
printf("
Insufficient arguments

[code]...

I'm also suppose to return the size of the input at the end.

View 3 Replies View Related

C/C++ :: Loading Int Data From File To 2D Array

Apr 28, 2014

Heres what I am suppose to do, So it doesnt seem hard to understand my messy code!

1. Gotta load the file "FactoryData.txt"
2. Load all values in my 2D array (array[5][3])
3. Print out the array to ensure that the copying went by well.

Heres my problem:

1. The for loops is REALLY off in my eyes. From my knowledge (correct me if im wrong), its suppose to be for(r=0;r<5;r++) not <=. BUT somehow im getting the results I want (in terms of formatting). HERE IS MY OUTPUT

Quote
300 450 500 510
510 600 750 627
627 100 420 530
530 621 730 200
200 50 58 100
100 83 4 5
Press Enter to return to Quincy...

View 8 Replies View Related

C++ :: Loading Data From File To RAM?

Mar 29, 2013

What is the most efficient (fastest) way to load data from a file on HDD to RAM? (which would allow to only load a limited section of that file - eg. load only half of the file etc.)

View 3 Replies View Related

C++ :: Loading Polymorphic Data From A File

Jun 11, 2014

What is the best / most efficient way to load polymorphic data from a file? I thought you could have an enumeration and for each item to load from a file you could have an integer at the start specifying the type of data, but I think there must be a better way I'm just not sure what.

Example of what I mean:

//The syntax isn't really that important for explanation
class base;
class a: base, b: base;
enum polymorphicType {
A,
B
};

and in the loading code you would have (this is the bit I think could be improved):

polymorphicType t;
File >> t;
if(t == A) {
newObject = new A;
} else if(t == B) {
newObject = new B;
}

I think there is probably a more efficient/better way of doing this I am just unaware of it.

View 4 Replies View Related

C++ :: Saving Array Data Into Text File

Dec 4, 2013

I have a program that saves all information temporarily into memory (into the array), however, I need a permanent save solution. I have the full program working correctly, formatted perfectly, but it's missing the file array to file output.

Essentially, whenever I'm presented with the menu I'll be able to add entries, search by last name, show the entire list, and exit and save. Whenever I select option 4 the program should save to a file "address_book.txt". Whenever I reload the program, it should load from "address_book.txt" and populate the array with the preexisting data.

My question is focused on how and where I should implement the file output. What I have thus far:

#include <iostream>
#include <string.h> //Required to use string compare
#include <fstream> //Eventually used to store array into file
using namespace std;
class AddBook{

[Code] ....

View 5 Replies View Related

C++ :: Sort Data From Text File Into Array As Its Being Read?

Feb 12, 2013

I am suppose to make a program that reads in data from a text file (integers only) and sorts them as it inserts them into an array of size 10. I did this using an insertion sort, which worked great. But now I am being told that I need the function has to read ALL of the numbers in the text file, not just the first 10, and I am not allowed to store them THEN sort, it has to be sorted as being stored.

This is what I have for sorting first 10

void sortArray(int iArray[])
{
string fileName = "";
fstream inFile;
int tmp = 0;

[Code]....

View 3 Replies View Related

C/C++ :: Loading 2D Array From A File?

Sep 10, 2014

The program is supposed to read in a text file, load it into an array and assign a character to each number in the array (so for this I'm thinking I'll be creating 2 arrays, an int array with the numbers read in from the file, and a char array with the characters assigned to the numbers). It will then print these two arrays. It's then supposed to go through the initial int array and search for any numbers whose values differ from their neighboring values by more than one, if such a value is found, it's supposed to give the number the value of the average of it's neighboring values. It's supposed to make all these corrections and then assign characters to these corrected numbers and print out both arrays.

How to load the array from the file. My textbook seems to do a good job of covering arrays and files, but it doesn't really bring them together and talk about building arrays from files. Here is what the file looks like, the first number is the size of the array.

10
7 6 9 4 5 4 3 2 1 0
6 5 5 5 6 5 4 3 2 1
6 5 6 6 7 6 8 4 3 2
1 5 6 7 7 7 6 5 4 3
5 5 6 7 6 7 7 6 5 9
5 6 7 6 5 6 6 5 4 3
5 6 7 9 5 5 6 5 4 3
5 5 6 7 6 6 7 6 5 4
5 9 5 6 7 6 5 0 3 2
5 5 5 5 6 5 4 3 2 7

And here is the code I have so far:

#include <iostream>
#include <fstream>
using namespace std;

[Code]....

When I attempt to compile this (I'm working on a Linux system), I'm getting several errors:

prog1.cpp: In function ?int main()?:
prog1.cpp:37: error: expected unqualified-id before ?[? token
prog1.cpp:39: error: ?numArray? was not declared in this scope
prog1.cpp:39: error: expected primary-expression before ?]? token

View 14 Replies View Related

C++ :: Loading Object Array From Input File?

Oct 13, 2014

I'm struggling loading a class (and it's two derived classes) from an input file. I'm trying to create an array of class objects (and derived objects) and then load them based upon what is in the file.

Main class: Code: class Book
{
protected:
string sTitle;

[Code].....

Basically if the getline get's a P it's supposed to create a new object using the PrintedBook derived class and then store it to an array, if the getline get's to the "A" it's supposed to create an AudioBook object.

What I'm struggling with is writing something to parse the file line by line and create the objects on the fly and then store them into the array.

View 5 Replies View Related

C++ :: Data Input Into A Text File While Not Deleting Original Data

Apr 19, 2013

I want to input data into text file while not deleting the original data in the file and I use something as

ofstream writefile;
writefile.open("example1.txt");
if (writefile.is_open()) {
for(j=0; j<N; j++) {

[Code] ....

But this will delete the original data.

View 3 Replies View Related

C# :: Loading Large Text Files In A RichTextBox (OutOfMemoryException)

Mar 31, 2014

I am creating a simple log parser (loads a text file and filters out unnecessary information, but has the option to show the full log) and I'm running into an issue with fairly large log sizes (50+mgs). I have seen a few recommendations from a stream to memory manged files and even alternate 3rd party controls.

I foresee a few issues with any of the non-third party solutions (which I would prefer to avoid third-party add-ins) such as the scroll bar not correctly reporting the relative length or position of the complete text in the box (when displaying only a portion of the file at a time) and in the stream solution where you read on scroll (as necessary) have not only the same issues, but how do you resume reading in the middle of the file? This also all assumes I would be periodically clearing the RichTextBox to keep the memory usage down to avoid an OutOfMemoryException (which I have been running into.)

View 14 Replies View Related

C :: Ferry Loading Using Two Queues - Can't Enter In Data After First Set Is Scanned

Feb 25, 2014

I'm trying to solve the ferry loading problem using two queues. My problem is I can't enter in data after the first set is scanned in, I'm assuming there is a problem with my loop, such that the scan function doesn't get called after one iteration. In the example I marked the data I can't enter. An example correct input would be:

correct input:
1 - can enter data20 4 - can enter data
380 left - can enter data
720 left - can't enter data
1340 right - can't enter data
1040 left - can't enter data

correct output: 3

my incorrect output: 1

Code:

#include <stdio.h>
#include <stdlib.h>
#include "my_linked_list.h"
#include "my_linked_list.c"
#include "status.h"

[Code] ....

View 6 Replies View Related

C++ :: Data File Handling Error - Character Strings Not Copied On Text File

Nov 24, 2013

I have this code for a computer project... (store management) but the character strings are not copied on text file..

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()

[Code] .....

Now when i run the program, it gives a error :::
ERROR
address 0x0

How can i write these strings to the text file?

View 2 Replies View Related

C/C++ :: Getting Data From File - Count Number Of Words In A Text File

Mar 27, 2014

I have a program I have to do that counts the number of words in a text file. I have tried the code on 2 computers now since my programming teacher told me the code was fine. Here is my code:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream infile;
infile.open("tj.text" , ios::in);

[Code] .....

View 4 Replies View Related

C++ :: Reading Data From Text File

Feb 25, 2013

I wanna read data from txt file with space divided each value like

1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 8.99506 9.98015 10.9901 11.992 12.9923 13.9932 14.996 16.0034 17.012 18.0255 19.0366 20.0485 21.0505 22.0664 23.0455 24.0383 25.0374 26.0439 27.0378 28.0376 29.0576 30.066

I know the size of the data is 2*500.

In matlab I can use like

fid = fopen('example.txt');
data = fscanf(fid,'%f,',1499500);

how should I write in C++?

View 3 Replies View Related

C++ :: Copy Data From One Text File To Another?

Jan 14, 2013

I need to copy data from one text file to another.This is how data in file looks like:

2 -3 8 5 0
3 5 1
2 -2 3 1 7 6
5 -3 15 0 1

I succesfully managed to copy those numbers but with one mistake.The last number is written twice. My output file looks like this:

2 -3 8 5 0
3 5 1
2 -2 3 1 7 6
5 -3 15 0 1 1

This is my code:

int a;
string str;
stringstream line;

[Code]....

View 3 Replies View Related

C++ :: Reading Data From Text File?

May 5, 2014

read some information from a text file. The program I'm working on is like a simple betting program.

What I need to read are:

match_code - team1 - team2 - odd1 - odd0 - odd2
139 Atletico Madrid - Real Madrid 2.853.40 2.35

But the spaces between datas are not known. We only know that both team names may contain more than one word and there is one space, exactly one dash and one more space (" – ") between team names.

Also match_code is an int and odds are double values.

while(getline(input, line)) {
istringstream ss(line);
ss >> match_code >> team1;
string temp;
while(ss >> temp) {

[Code] .....

In that missing part, I need to get the second word of team name if there is one; and the three odds that are odd1 odd0 and odd2.

View 2 Replies View Related

C++ :: Reading Data From A Text File?

Feb 10, 2015

Each line of the text file has first name, last name, and a salary. Something along the lines of this:

john doe 4000
bob miller 9000

I want my program to take the first name, last name, and salary of each line and assign them to strings. I have tried this so far:

while (inFile){
inFile >> firstName;
inFile >> lastName;
inFile >> grossPay;
cout << firstName << " " << lastName << " " << grossPay << endl;
}

When it outputs the names and the salary, the last line of the text file gets output twice by the program.

View 1 Replies View Related

C++ :: Parsing Data From Text File?

Aug 26, 2014

Requirements in filtering the text file.

1. first my professor required me NOT to change the MAIN function(because he made it)

2. I have to make 3 getlogs() STRING FUNCTIONS:

a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE
b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01"
c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";

3. all COUT should be in the MAIN FUNCTION

TEXTFILE CONTAINS:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType

[Code] .....

my codes so far:

//MAIN
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>

[Code].....

View 1 Replies View Related

C :: Record Data (add / Delete) In Text File

Aug 24, 2013

I'm still learning intro to C language. Currently I'm having problem with my code. The task is to ask user to input information about staff and write them into a text file. The problem occur when:

1) output in text/.exe file display random characters.

2) Data obtained from New_Staff unable to pass into Export_Profile.

3) a new output will overwrite the existing information in the text/.exe file

4) the delete function unable to delete correctly after the first time i delete a staff information in text file.

The code is as follows:

#include <stdio.h>
#include <stdlib.h>

void Menu();
void New_Staff();
void Delete_Staff();
void Export_Profile();

[Code] ....

View 4 Replies View Related

C++ :: Reading And Writing Data In Text File

Jan 5, 2015

Code to write data(Double type e.g 12345.67891) in text file like pattern given below. Remember to put tab between each column.

-----------------------------------------------------
Column1 Column2 Column3
Value 1 Value 2 Value 3
Value 4 Value 5 Value 6
Value 7 Value 8 Value 9
----------------------------------------------------

& Also how to read data from this file.

View 3 Replies View Related

C# :: Adding And Displaying Data From A Text File

Mar 6, 2014

Is it possible to display data from a textfile and also save data in to a textfile, reason being is for me to create back-ups of data into a textfile hidden somewhere in a safe location in the local disk or server in case of database error and failure.

View 3 Replies View Related

C++ :: Not Able To Read Data From Text File And Convert It To Integer

Mar 25, 2013

I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:

20 40 20 25 30

20 30 40 20 25

20 40 20 25 30

20 30 40 20 25

30 40 40 30 40

I am using getline, and then converting it to int by using atoi. But my code is not working.

Code :
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 10 Replies View Related

C++ :: Writing Text Data To A Binary File With Fstream

Jul 9, 2014

fstream ifs;
ifs.open ("data.str", ios::binary | ios:ut);
char *data1 = "data1";
char *data2 = "data2";
ifs.write(data1, strlen(data1));
ifs.write(data2, strlen(data2));

when i this,data2 is not going under data1, i thought each write starts on a new line?

View 4 Replies View Related

C :: Unable To Read Data From Text File And Print It

May 12, 2014

I am having trouble in reading data from my text file and print it out exactly like how it looks like in the text file. The problem im having is it will not read the last y Coordinates of the point. it keep reading the second last point for y coordinates which is wrong.

my text file is
0.0 0.0
0.0 1.0
1.0 0.0(but it read until here)
0.0 0.0(suppose to read the last point which is here)

For your information, this is my 1st year degree assignment in C programming. It is to create a program which can read text file (manually create) and print it out in a program and calculate the area for the polygon using ADT function ( .c and .h files)

*This is the code for my read file function*

Basically this accepts a Polygon and a file pointer as parameters. It reads the polygon point data from the file, pass the read data to plg_new() to create a new Polygon and returns the new Polygon created.

Code:

polygon *plg_read(polygon *New_polygon, FILE *Coord) {
int i;
int numberofvertices=0;
int count=0;
char filename[50];
double xCoor[50], yCoor[50];

[Code]....

This is the second function my polygon new code. This ADT function basically creates a new Polygon with malloc(), initialize all ADT data members with its parameter values and returns the Polygon.

Code:

polygon *plg_new(double *xCoordinates, double *yCoordinates, int numberOfVertices) {
int x;
polygon *New_poly = (polygon *)malloc(sizeof (polygon));
if(New_poly->xCoordinates == NULL || New_poly->yCoordinates == NULL) {
free(New_poly);

[Code]....

This is the rest of the code if you need to refer to other codings.

Code:
/**
*@file polygon.c
*@brief Functions for polygon / Struct has polygon numberOfVertices, polygon *xCoordinates and polygon *yCoordinates
*@author: Tan Xian Yao
*@id: 4323440
*@date: 22/04/2014
*/

[Code]...

View 6 Replies View Related







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