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


ADVERTISEMENT

C++ :: How To Read / Edit CSV File And Continue From Last Login

May 5, 2014

I am working on a program that will do several mathematical calculation and will store the data into a csv file.The one below is just a prototype version of this.In my program,I will store my csv file as (current-date).csv using time.

With this in mind,I want my program to first check does (current-date).csv already exists.If not,the program runs normally and output all the data into the csv file.

However if (current-date).csv already exists,I want my program to read and edit that particular csv file,by skipping part1 in my code(name,id N etc.) and start with prompting the user for numbers straight-away.

In other words, if (current-date).csv already exists,the user should continue outputting the numbers from where the user last left before last termination instead of outputting the name,date & etc into the csv file again.

Eg: if no=22, continue inputting values from no=23 till terminating the program again and storing the values correctly into the csv file.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <locale>
#include <string>
#include <sstream>
#include <time.h>

using namespace std;
// Program to read date N store it as currentdate.csv

[Code] ....

View 6 Replies View Related

C++ :: Using Arrays As Sources Of Data For Arrays In A Structure?

Feb 6, 2014

I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

Code:

int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS

[Code]....

View 2 Replies View Related

C :: Read A Line From Screen / Takes ASCII Values From Entered Text And Edit It

May 10, 2013

This is a small program that reads a line from the screen, takes the ASCII values from the entered text, and edits it. Next, the ASCII values are reinterpreted (am i misspelling?) as text, and displayed. However, my final output has (allways?) at least 7 characters, even if you enter only one. I'm also trying to accomplish, that the part of the string which isn't filled, will be printed empty. In spaces.

compiled with -std=c99.

Code:
#include <stdio.h>
int main(){
int maxsize;
printf("How long is your message?

[Code] .....

View 6 Replies View Related

C++ :: Passing Structure Arrays To Functions?

Oct 31, 2013

Description: Use functions and structures to simulate storage in a warehouse

*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

[code].....

I keep getting a linker error on every function. what am I doing wrong?

View 2 Replies View Related

C/C++ :: How To Assign Values From Text File To Structure Of Arrays

Sep 5, 2014

have to do an election program in C.

There are 7 candidates and 365 votes in total. I need to do this using an array of structures. I need to read from a text file each of the names of the candidate and the number of votes they get. At the end i need to output the winner of the election.

Here is a sample of my code so far

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct candidates {
char name[20];
int votes;

[code]....

Here is a sample of my text file:

Robert Bloom
John Brown
Michelle Dawn
Michael Hall
Sean O’Rielly
Arthur Smith
Carl White

1 2 4 5 1 2 3 4 4 1 2 3 7 4 4 5 3 7 7 7 7 7 7 7 7 7

Each candidate gets +1 vote for their number electionCandidate[0] for each one he gets one vote and so on for the rest. 365 voters in total.

I was able to input the name for each Candidate from the text file. Now the problem is putting each vote to the corresponding candidate. Also any vote that is above 7 is a spoilt vote which i am trying to count in the above code. The code compiles but it crashes.

I am using while(!feof) but it seems that its not working or this is not the correct way.

View 6 Replies View Related

C :: Read From File Into Structure?

Nov 24, 2013

When I tried to run my code I keep getting a "Segmentation fault".

I am trying to write a code that read from a file and put the data into a structure.

The file look like the following:
2001,ABBIGAEL,5
1994,ABBIGAIL,5
1996,ABBIGAIL,8
1997,ABBIGAIL,13

The file have 31 lines.

Code:
#include <stdio.h>
#include <string.h>
int main() {
/* Define a daydata structure */
typedef struct {

[Code]....

View 4 Replies View Related

C :: How To Do Arithmetic On Structure Members Read From A Text File

May 19, 2014

I am trying to use arithmetic on structure members read from separate text files into separate functions. I'm trying to do the math in the main function after calling the other two functions. I'm trying to divide nato_attack by pact_defence.

The warning I'm getting is: both are being used uninitialized in this function.

The goal is to read/write the info in the text files and to use them as any other variable, i.e. add, subtract, etc. in other locations in my code, i.e. functions, modules.

I "borrowed" most of this code from a youtube lesson and modified it for my needs.

Below is the contents of the two text files and my code.

This is for NATO
6
12 4th_mech_div mech div 14 16 7
12 5th_mech_div mech div 10 8 7
12 3rd_mech_div mech div 5 6 6
12 1st_mech_div mech div 4 6 7
12 2nd_mech_div mech div 12 14 7
12 6th_mech_div mech div 8 12 6

This is for Pact
3
10 1st_Guards armor div 12 8 6
10 2nd_Guards armor div 12 9 6
10 3rd_Guards mechanized div 10 9 6

Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *unit_id;
char *unit_type;
char *unit_size;

[Code] ....

View 9 Replies View Related

C++ :: Read Input From User And Then Store In Structure Variable

Apr 6, 2014

My program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int DESCRIPTION_SIZE = 100, DATE_SIZE = 20;
struct inventory {
string description[DESCRIPTION_SIZE];

[Code] .....

I left out the other functions. The error reads "no matching member function for call to 'getline'.

View 6 Replies View Related

C/C++ :: How To Get Array Of Structure Code To Read Form A File

Dec 10, 2014

I tried to make the program read from a file text the first name or last name but o cant seem to get it. i tried alot of different ways. how can i get the array of structure code to read form a file?

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int NUM_STUDENTS = 17;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;

[Code] .....

View 14 Replies View Related

C :: Writing Structure Array Bytewise To Binary File And Read It Back

Aug 21, 2014

I would like to write a complete structure array to a file and read it back, recovering all the data. I have tried the following:

Code:

#include <stdio.h>
#include <string.h>
#define NUM 256
const char *fname="binary.bin";
typedef struct foo_s {
int intA;
int intB;
char string[20];

[Code]...

//---------------------------------------------------- but the mac field is reading back some random value repeatedly. Why is that? And how do I fix this?

View 8 Replies View Related

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 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 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++ :: 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++ :: 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# :: 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 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++ :: 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++ :: 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++ :: Program To Return Structure

Jan 9, 2014

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
struct name {
int first;
int second;

[code] .....

whats wrong in the program i tried to return struct.

View 2 Replies View Related

C++ :: Data Structure - Program Using Stacks

Nov 3, 2013

Given a set of different types of paired symbols; determine whether it is balanced or not (the opening and closing version of each type are paired correctly). Any other type of characters may appear in the input will be neglected.

For example:
(**(*[*])****) is balanced, also [{}**[]**()]** is balanced. But ((*{*)*}) is unbalanced as well as [()***[]***{*(*)}.

Write a C++ program that requires a string containing and expression as an input from the user and check for balanced bracket pairs using stack data structure.

Here is my code which give me nothing when I run it.

#include <iostream>
#include <string>
using namespace std;
class CustomStack {

[Code] ....

View 1 Replies View Related

C/C++ :: Program That Uses Priority Structure Squishing Bug

Jun 8, 2014

quishing some bugs, and also how to go about squishing these bugs?

#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>

[Code].....

Here are the errors after compiling the program.

View 7 Replies View Related

C :: Predictive Text Program - Data Structure

Jan 19, 2014

Been given an assignment to create a predictive text program. What data structure I should use for this and the steps I should take when I make the program?

View 12 Replies View Related







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