C :: How To Read A File Into Parallel Arrays

Nov 3, 2014

I have trouble reading data from a text file to parallel arrays. the text file (album.txt) has this format:

Code:

(song1 title)
(song1 artist)
(time1)
(song2 title)
(song2 artist)
(time2)
.
.
etc

I want to store these data into three arrays:

title [], artist[], time[] this is what I have so far:

Code:

#include <stdio.h>
#include <string.h>
#define SIZE 9999
int main ()
{

FILE *tFile;
char title[SIZE];

[Code]...

the problem is that each array reads the whole text? I want to store artists name in char artist[] .. titles in char title[] and so on

View 5 Replies


ADVERTISEMENT

C++ :: How To Read External File Into Parallel Arrays

Dec 8, 2013

I have an external file that I would like to read from this file and place the values into parallel arrays. The file has these values:

Rams
Titans
23
Patriots
Rams
20
Steelers
Seahawks
21

View 1 Replies View Related

C++ :: How To Read Multiple Elements In File To Parallel Arrays

Apr 19, 2013

I have a txt file that looks like this:

Student ID:97707; Grades: 87.73, 90.41, 91.74, 95.04, 99.13; Name:Davis, Artur
Student ID:23628; Grades: 58.09, 65.18, 68.62, 68.62, 98.05; Name:Davis, Susan
Student ID:49024; Grades: 18.37, 66.06, 68.07, 80.91, 96.47; Name:DeGette, Diana

-I need to read the id, grades and names;
-The id to a separate array
-The grades to a 2-d array
-And the names to a c style string.

Where do I start, im having trouble read the dummy to start

int main() {
char filename[15] = "ex.txt";
string names[MAX_NAMES];
double grades[MAX_ROWS][MAX_COLS];
int id[MAX_IDS];
int index = 0;
ifstream fin;

[Code] .....

View 3 Replies View Related

C/C++ :: Parallel Arrays From File

Mar 31, 2015

#include <stdio.h> /* fopen, fclose */
#include <stdlib.h> /* exit function */
#include <string.h> /* string library */
#define STRSIZENAME1 41 /* length of name */
#define STRSIZENAME2 100 /* amount of names */
#define STRSIZEAGE 100 /* amount of ages */

/* Name: main */
int main(int argc, char* argv[]) {
[Xode] ....

This is the code I have so far. The goal of the assignment is to sort two parallel arrays, one with names and another with their ages, at the same time to alphabetize them. I am stuck with trying to pull the data from the file itself and concatinating it. I have searched ways to do so and this is the best I understood. So the error is it will get me the first person's name, but it won't get the age and move to the next line in the file. It just keeps repeating the same thing and I can't figure out why.

I attached the sample file with names and ages to view the format of the text file itself.

PS the other defined variables are used later for sorting the data. right now I am just trying to get the data itself and put it in an array but between my book and the internet I can't seem to store the data properly. That is also why I am printing it in the while loop as well so I can see what my arrays look like but I will take that out too once I know the data is good

Attached File(s)
peoplefile.txt (157bytes)

View 2 Replies View Related

C++ :: Inputting TXT File Into 2 Parallel Arrays Via Void Function

Nov 10, 2014

I have a .txt file that I need to input into two parallel arrays. The first array needs to be on dimension and the second needs to be two dimensions.

This is a sample from the .txt file:

Australia62.762.163.359.7
Austria052.853.154.6
Belgium30.430.327.525.3
Canada61.356.257.754.5
Chile026.425.431.1
CzechRepublic038.327.325.2
Denmark65.067.162.355.0
Estonia51.732.929.834.3
Finland55.242.942.143.3
France35.728.330.228.8
Germany56.447.242.646.6
Greece30.326.925.013.1
Hungary032.521.818.6
Iceland068.271.666.0

this is what I have for code so far:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
const int SIZE = 40;
const int COLUMN = 5;
void getData(ifstream& inf, string n[], double tstData[][COLUMN], int count);

[Code] .....

when I compile and run the code and have it display it does not read the first item into the 1-d array, instead it appears to read the 4th number from the left into the 1-d array and then into the second spot in the 2-d array, then again in its proper place and finally it has this number repeating through the rest of the arrays:

-92559631349317830000000000000000000000000000000000000000000.00 followed by the number 59.7 from the .txt and the long number again.

View 10 Replies View Related

C++ :: Parallel Arrays And Files

Mar 10, 2014

I am trying to learn about parallel arrays and files. I believe that I wrote a program that properly writes the data of the arrays into a file, but I am not quite sure how to take the next step and make a second program by bringing in the file I created and reading the information of the file back into two arrays to display them.

Code:
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;

[Code] ....

View 5 Replies View Related

C++ :: Declaring Parallel Arrays As Functions

Oct 23, 2013

i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function?

pointtwod.h
class PointTwoD {
private:
int xcord,ycord;
float civIndex;
LocationData locationdata;

[Code] ....

when i compile the error message i get was even when i i put in int xord[]; in my PointTwoD.h file:

PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'

PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)

PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token

View 1 Replies View Related

C/C++ :: Grade Converter Using Parallel Arrays

Apr 8, 2015

I am attempting to reconfigure a working code that before used while loops and if statements to convert a numeric score to a letter grade. I now wish to take this same code however I want to change the char convertGrade(int numScore) to simply use a parallel array as a replacement to the if statements.

The array needs to consist of 3 arrays of fixed size 5:
int minScores[SIZE]
int maxScores[SIZE]
char letterGrade[SIZE]

I know the declarations need to go in the function convertGrade but this is the first time I have worked with arrays and I am having trouble trying to figure out how this array will replace my previous if statement.

In order to access the array elements I need to write specifications such as
minScores[i]
maxScores[i]
letterGrade[i]

(where i = 0, 1, 2, 3, or 4)

#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int getScore(void);
char convertGrade(int numScore);

[Code] .....

View 5 Replies View Related

C/C++ :: Understanding Parallel Arrays And Displaying Them?

Apr 14, 2014

So the point in this code is to promt the user to enter a product ID. It then should search the ids array and display the corresponding price and quantity from the prices and quantities arrays. I'm sure this is quite simple but I am new to programming and having trouble understanding arrays. All it is doing is giving me the first subscript when I input a -1.

//Advanced34.cpp - displays the price and quantity
//associated with a product ID
//Created by Scott Knight on April 12, 2014
#include <iostream>
using namespace std;
int main() {
//declare arrays and variables
int ids[5] = {10, 14, 34, 45, 78};

[code]......

View 5 Replies View Related

C/C++ :: Summing Two Parallel Arrays To Display Sum Of Both

Aug 17, 2013

I am having a problem with my program to calculate the GPA of a student. The problem that I am having is that I am not able to get my Total Point Value to display the sum of the two arrays. The multiplication for the array is correct and will display correctly, but instead of putting the total into the accumulator it will display the totals in a column. I have tried moving the coding for the calculation out of the loop that converts the letter grade into a point value,and placing it in it's own loop, but I still get the same display output. Below is the code that I have so far. I still have a few elements to add to the code, but they will be easy once I get this display to work right.

#include <iostream>
#include <iomanip>
#include <fstream>  
using namespace std;  
// Global const    
// prototype    
int main () {    
// Varialbes, Arrays

[Code] ....

View 1 Replies View Related

Visual C++ :: Sorting Parallel Arrays?

Apr 4, 2014

Class programming project where we declare two arrays, a sting array containing the names of the boroughs and an int array which which holds accident number for each borough. The main function calls getNumAccidents() function to fill the array. it then calls findLowest() to learn which borough had the fewest accidents. It should print out the accident numbers for each borough and then out the borough and accident number with the fewest accidents.

I'm able to get the program to kind of work. When I run it everything works fine but I am not able to get the arrays to sort and match up correctly..

#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
using namespace std;
class combineSort {
public:
combineSort() {

[code]...

View 14 Replies View Related

C/C++ :: Comparing Element Values In Dynamic Parallel Arrays

Oct 30, 2014

I've been working on an assignment that deals with newspaper advertisements. I have two arrays:

categoryCode (the code for the advertisement's category such as pets, cars, etc) and
numWords (number of words in the ad).

The arrays are dynamic.

My assignment has the category listed each time there is an ad associated with it and then its number of words for that ad. If this were a real-world issue I would want my output to list each category only once despite how many ads were in it, list how many individual ads are in the category, and its total number of words for the ads in that category. When using parallel arrays, is there a way to do this?

Let's say I have categoryCode with three elements {5, 5, 7} and numWords {10, 12, 15}.

How would I make the numWords add together only when the categoryCode values are the same?

I would want the output to print:
Category 5 Ads 2 Words 22
Category 7 Ads 1 Words 15

rather than how my instructor is having us do it like this:
Category 5 Words 10
Category 5 Words 12
Category 7 Words 15

I think I'm getting hung up because my mind is confusing the element's location in the array with the element's actual value and I'm probably making this harder than it should be. How would I compare the categoryCode values in a dynamic array? If it were a fixed size I think I could just compare categoryCode[0] to categoryCode[1] and so on, right? But in this case I'm not sure how I would go about that.

View 6 Replies View Related

C :: Declare Two 1-dimensional Parallel Arrays Of Integers That Will Hold The Information Of Up To 10 People

Jul 30, 2014

In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?

Code:
#include <stdio.h>
int main() {
//Define Variables
float Age_Data[10],Weight_Data[10];
float Age_Input,Weight_Input;

[Code] .....

View 3 Replies View Related

C :: Read Text From A File Into Arrays To Set Categories

May 15, 2013

I'm making a Jeopardy game and when I read text from a file into arrays to set the categories, questions and answers a couple of the strings are not terminating and they are printing that junk box thing at the end.

When I use the debugger and print the problem strings they are showing up as "Thanksgiving21" or "Calvin Klein21" but all the other strings aren't having that problem.

Then for example I will change "line[strlen(line)-1] = '';" to "line[strlen(line)] = '';" and other strings will have that problem but not those stated ones. I'm using line[strlen(line) - 1] = '' to get rid of the newline fgets appends on the end of the strings.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE *file = fopen("questions", "r");
char *string[66], line[150];
int idx;

[Code]...

View 6 Replies View Related

C/C++ :: How To Make 2 Arrays Put Them In A File Then Read Them From File

Mar 11, 2014

I have to read 2 arrays, put them in a file. Then make a 2nd program, read the data from the file and show the 2 arrays. I believe I have fully completed the first program, but I am still working on the 2nd one. On the 2nd one I am trying to create a function that displays the data from the file.

//first part
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int num_stores = 3;
const int col = 4;
const int size=4;
void showData( const string[], const int[][col], int size );

[code]....

View 3 Replies View Related

C :: Read Specific Values From A File And Store Them In Arrays

Apr 14, 2013

What i try to do is to write a code which reads some specific values from a file and stores them in an array. My File looks like this

Code:

XFOIL Version 6.96
Calculated polar for: Myfoil
1 1 Reynolds number fixed Mach number fixed
xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 0.200 e 6 Ncrit = 4.000
}

[code]...

View 11 Replies View Related

C++ :: Read Input File Of Data And Store Them In Arrays

Nov 5, 2013

Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

Hours Pay Rate Employee Number First Name Last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();

[code]....

View 9 Replies View Related

C/C++ :: How To Read Information From A Text File And Store It Into Arrays

Mar 28, 2014

how I can read information from a text file into an array so afterwards I can display the array and it will show the contents of the text file?

the information inside my text files consist of names and numbers like so: "Collins,Bills 80" should I separate the numbers and names into two separate text files one for names and one for numbers?

My code so far is this:

#include <iostream> //for cin and cout
#include <fstream> //for input/output files
#include <conio.h> //for getch

[Code]....

View 2 Replies View Related

C++ :: Read Data From A File Then Store / Search And Display Using Classes And Arrays

Apr 12, 2013

A company uses two text files: one to store employees' details and another to log their sign in/out time.

The details file - called details.txt" has the following format: ID, Name, Date of Birth, SSN, Department, Position - separated by spaces.

An extract from the file looks like this:

10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant

"timelog.txt" contains daily logs of when employees arrive and leave. It has the following format: ID, Date, Arrival Time, Departure Time - separated by spaces. An extract from the file looks like this:

10 2/11 0900 1700
3 2/11 0930 1730
1 2/11 1100 2000
2 2/11 1000 1530
17 2/11 0900 1700
10 2/12 1000 1830
3 2/12 0930 1730
1 2/12 1100 1900
2 2/12 1030 2000
17 2/12 0900 1700
15 2/12 1100 1600

I have to write a program that searches for specific records using some search parameter, and displays them. Ok first i have to read the data from the files and store them. this is what i have so far....

#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>

[Code] ....

I know my class and array code is totally wrong i dont know how to store the data for the info is in integer and string form... do i use strings, arrays?

View 1 Replies View Related

C# :: Read And Write 2D Arrays Into Fields?

Nov 17, 2014

reading and writing 2D arrays I've been trying out a few tutorials using FileStream but I couldn't get any of them to work.

Anyway what I'm trying to do is save the playerArray to a .txt file and then read from that .txt into the fields within the GUI. This is supposed to act as a database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 2 Replies View Related

C++ :: Read N Data Items Into Two Arrays (X And Y) Of Size 20

Apr 1, 2013

Trying to do a homework assignment for a class and how to read a file into an array. I've looked in our book and on several other forums and cant seem to find any examples of this. Below is the assignment I'm working on. I have a shell of the program that I can get to run, but getting a .txt file to read into an array is something I cant seem to figure out how to do.

Write a program to read N data items into two arrays, X and Y, of size 20. Store the product of the corresponding pairs of elements of X and Y in a third array Z, also of size 20. Print a three column table that displays the arrays X, Y, and Z. Then compute and print the square root of the sum of the items in array Z. Compute and print the average of the values in array Z and print all values above the average of array Z. Determine the smallest value in each array using only one function.

Use the two data files named DATAX.TXT and DATAY.TXT.

You must use functions for the reading of the data, computing the average, printing the three column table and printing the values above average.

View 3 Replies View Related

C/C++ :: Program That Can Read And Edit Structure Arrays

Feb 5, 2015

writing this program where you can search a structure array for existing elements, add new elements to the structure array, and find and display entire elements of the array structure and all.

Right now I am stuck on adding new elements to the structure array.

#include <iostream>
#include <string>
#include <iomanip>

[Code]....

Any methods to displaying the a array structure or editing it ....

View 6 Replies View Related

C# :: Convert Dictionaries To Arrays To Read And Write Sequentially

Nov 27, 2011

Code:

// declare child arrays
public string[,] childcolor;
public string[,] childgeneo;
// create dictionaries
public Dictionary<string, int> colors = new Dictionary<string, int>();
public string color; // name for dictionary
public Dictionary<string, string> geneo = new Dictionary<string, string>();

[Code]...

I'm getting "field' is used like a 'type' error on jw.childcolor which causes other parts to error out.

How do I fix this & why am I getting the error?

I want to convert the dictionaries to arrays to read & write sequentially.

View 4 Replies View Related

C :: Read Contents Of A File Using Low I/O Read Statements

May 15, 2013

I want to read the contents of a file block (512 bytes) by block using low I/O read statements. Each record is 64 bytes long and has a pre-defined structure. The first 4 bytes are an unsigned integer; the next 20 bytes are ascii text, etc.

I have a buffer which I can access with buf[0] to buf[63] to read the first record and then buf[64] to buf[127] for the second, etc. However, I was wondering how to map a record so that I can refer to an integer as an integer and a float as float, etc. I can't create a struct and move the 64 bytes to it, as I will have alllignment/padding problems.

What is the standard way to deal with records in C?

View 5 Replies View Related

C++ :: Parallel OMP With Many New Operators?

Jul 14, 2012

I have a code that uses multi threads using OMP. However, Inside the code I allocate too many memory using "new".

I know that the memory allocation using new must be done in serial. Therefore I am not getting a good performance out of the multi-threaded program.

I thought about allocating a big memory only once, and then advance the pointer every time I need to allocate a small memory.

For example, if I need to allocate chunks of 7 doubles:

Code:
main_memory = new double [10000];
double* x1 = main_memory;
main_memory+= 7;
double* x2 = main_memory;
main_memory+= 7

However, I do not know how to handle the memory deallocation. Beside, this is not thread safe method because main_memory is shared by all threads.

May be there is a boost library that does this, which I am not aware of.

View 3 Replies View Related

C :: Parallel Port Programming - On / Off LED

Sep 9, 2014

I try to ON and OFF the LED's via parallel port. I connect the cathode of LED's with pin number 18 that is ground and anode of each LED is connected through a 1K resistor to pin 2 to 8. I write the following programe

Code:
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORTID 0x378
void main(){
outportb(PORTID,0x00);
getch()
}

But when i connect the LEDS to the parallel port all the LEDS are LIT while i also change the 0x00 to 0xff and so on. But no effect on the LED's.

View 8 Replies View Related







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