C++ :: Loop To Read In Data And Check Data

Oct 8, 2013

struct receivers
{string fname, lname, team,;
int receptions, yards, TDs, longest,rec20, fumbles, yac, firstdown;
double, averagepergain, averageperrec
}

View 2 Replies


ADVERTISEMENT

C++ :: Using Loop To Read In Data From A File?

Oct 30, 2013

My function is only reading the first line of numbers even though I have the loop to keep returning to it in main(). How do I have it read from the file until it runs out of data to retrieve?

File being read

90 83 94
72 65 81

File being sent the data(Only the second average is correct, working on the first)

Student Information
Student IDGradeAverageLetter Grade
1895612
90 83 94
289
90 83 94

#include <fstream>
#include <iostream>
using namespace std;
ifstream infile;
ofstream outfile;
void grades(int&,int&,int&); // Grades from the input file
int myavg(int,int,int); // Calculates the Average of the 3 grades

[Code] .....

View 8 Replies View Related

Visual C++ :: Use For Loop To Read Certain Data From Txt File And Print To Console

Sep 28, 2014

I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.

Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88

The data may vary but it's always in this format.

View 14 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Check Wrong Input Data

Jan 20, 2013

i'm making a for loop for a mini game which required the user to enter the input number.Let say if the user accidently entered a character instead of integer the whole program will go haywire so is there anyway to check for the error and prompt the user to input the data again?Here is the simple program...

for(row=0;row<4;row++)
{
printf("Enter Row%d:",row);
for(col=0;col<4;col++)
{
scanf("%d",&num[row][col]);
}

View 1 Replies View Related

C++ :: Data Structure - To Check If A Set B Is A Subset Of A Or Not

Feb 9, 2013

To check if a set B is a subset of A or not. Which data structure to be used to store set A for quicker response(linked list/hash map)? What if I want to check intersection also?

View 1 Replies View Related

C++ :: How To Check If Data In Struct Has Changed

Nov 21, 2013

I am working on this project where I need to see if data in a struct has changed and if so I need to do something. With that being said, is there a way to check to see if data in a struct has changed. My first approach was to make a copy of the struct and compare the original struct with the copy but I was having problems with the operator==.

View 2 Replies View Related

C++ :: How To Check For Data Type When Input Value Into Program

Apr 11, 2013

How would I check for proper data type when someone is to input a value into the program? Ex:

int i;
string a;
cout << "Enter a number: ";
cin >> i;
cout >> "Enter a string: ";
cin >> a;

How would you check to make sure that int i would be an actual number and not a letter like "a"?

View 4 Replies View Related

C++ :: Program To Search Soccer Players Data To Check Whether Name Supplied By User Is On That List

Oct 29, 2014

Write a program that will search soccer players data to check whether a name supplied by the user is on that list. For doing the search, the user may provide either the player’s full last name or one or more starting letters of the last name. If a matching last name is found, the program will display the player’s full name and date of birth. Otherwise, it will display “Not found”.

Requirements specification:At the start, the program will ask the user to enter information about 10 soccer players constituting soccer player data. Each soccer player data will consist of the following fields:

Last name
First name
Birth month
Birth day
Birth year

The user will be asked to enter each soccer player data on a separate line with the field values separated by a space.

Once the data is entered, the program will display a menu of choices as below:

Chose an option:

(1 – input data, 2 – display original data, 3 – sort data , 4 – display sorted data 5 – search by last name 6 – exit the program )

If the user chooses option 1, the program will ask the user for a data and populate the array of structures that will hold the data for each of the soccer players.

If the user chooses option 2, the program will display data in the order provided by the user (original data).

If use chooses option 3, the program will sort data by last name.

If user chooses number 4 the program will display the data sorted by last name.

If the user chooses option 5, the program will ask the user to enter one or more starting letters of the soccer player’s last name. It will then search the soccer player data for the matching last name. If a match is found, it will display the first player found with the matching pattern. If a match is not found, the program will display “Not found”. If the user enters two forward slashes (//) for the last name, it will no longer search for the name. Instead it will display the main option menu.

If the user chooses option 6, the program will display “Thank you for using this program” and will end.

Why my program isint executing correctly. Here is what i've so far . . . .

#include <iostream>
#include <string>
using namespace std;
struct data {
string lname;
string fname;
int birthmonth;
int birthday;
int birthyear;

[Code]...

View 3 Replies View Related

C++ :: How To Write A Data Loop

Feb 14, 2013

I need to write a data input for one of my class assignment. Would this be considered a data loop?

while (cin >> number)

View 4 Replies View Related

C :: Data Read And Write

Dec 22, 2013

My program needs to receive data continuously from one process and the received data is read continuously by another process.But when I am trying to create a pipe using mknod on fat32 file system in linux , it throws an error saying "mknod: operation not permitted".

View 3 Replies View Related

C++ :: How To Read Data From TXT File Into Array

Feb 25, 2013

I wanna read a txt file like this
1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 .....
and fill the array P[i][j] with the data.

I try to use

if (myfile.is_open()) {
//for (int i = 0; i < 1; i++)
//{
getline (myfile,DMArray[0]);
cout << DMArray[i] << endl;
//}
myfile.close();
}

But this read the data into a string. How should i do with this string. Besides I know the dimension of the data I am reading.

View 1 Replies View Related

C/C++ :: How To Read Data After EOF Command Has Been Executed

Mar 26, 2013

I have to write a program in c which allow user store data in a file as well can edit it.... i have written the following program, but the program cannot read data after EOF command has been executed....

#include <stdio.h>
main() {
FILE *fp;
char c;
int ch;
char filename[20];
printf("enter filename");

[Code] ....

View 2 Replies View Related

C/C++ :: Read Bytes From A Data File

Dec 5, 2014

I am a member of a group still developing the Microprose European Air War game. We have the source code and permission to do this. As the code dates back to 1998 I use Visual Studio 2006.

I have written many programs in Visual basic, and have the following one to read the airbase value in the "targets.dat" file. The file has a four byte header containing the number of tatgets, and a 32 byte data block containing the data for each target.

Private Sub Command1_Click()
List1.Clear
Dim nt As Long
Dim a4() As Long  
Open App.Path & " argets.dat" For Binary Access Read As 1
'read and display the number of targets  

[Code] ....

Despite many attempts I cannot write the C equivalent of this code into the eaw.exe source. All I really need to know is how to open the 'targets.dat' file and how to get the value of a byte (or integer, or long) at a given position as in the "Get #1, k, a4(n)" line.

View 1 Replies View Related

C++ :: Reaching Data Of Different Array Using Pointer In Loop

Jul 31, 2013

I have 3 arrays named: abee1 , abee2, myarray.

I have loop that want to call abee1 , abee2 one each time and copy myarray into it . It means that I reach the name of abee1 to abee2 in the loop for doing this. I made the name of each one by using strings ( abee1 , abee2) in the loop. In the last I want to copy the myarray into the abee1/2 using pointer.

I do not know what to do after the line "string arrayname = "abee" + String;".

#include<iostream>
#include<string>
#include <sstream>
using namespace std ;
int abee1 [4] [4] ;

[Code] ...

View 1 Replies View Related

C :: Read Link List Data From File

May 7, 2013

i write this program and every things work correct except when i want to add data of file to the link list .when i add the data to the link list by add_to_linked_list() every things work correct but when i use read_linked_list_from_file() it doesn't work

Code:

#include <stdio.h>
#include <stdlib.h>
// double linked list structure
struct linked_list {
struct linked_list *next;
struct linked_list *prev;
char *value;
};

[code]....

View 2 Replies View Related

C :: Switch To Different Data Types - How To Read One Parameter

Jul 11, 2013

Is there any way to make a switch in C. That I can choose between different data types? For example, at the moment I need to know how to read one parameter. It must recognize if it is a boolean or uint32.

View 4 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++ :: Read A File Into 2D Array And Display Data

Nov 15, 2014

I am currently working on a problem where I read a file into a 2D array, and display data. If you saw my code earlier, this is the same problem, but I am now further along.

The file (90 characters) looks like this:
S
R
R
S
R
R
R
R
S
S
....

The "R" resembles rainy days, the "S" resembles sunny days, and the "C" resembles cloudy days. There are 90 characters in the file. The first 30 are for the month of June, the next 30 are for the month of July, and the last 30 are for the month of August. The 31st day of the months are NOT included.

I read the data into a 3 x 30 array, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the number of days in each month.

Now I need to create a function that creates a report and displays, for each month AND for the whole 3 month period:
1) The number of rainy days
2) The number of cloudy days
3) The number of sunny days
4) Which of the 3 months had the largest number of rainy days

Here is my code so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MONTHS = 3;//Number of months

[Code] .....

There are no compiling errors, but I am not getting the data I want. My rCount and cCount variables end up being 0, and my sCount variable is 90.

View 4 Replies View Related

C++ :: How To Read Data Of Particular Student And Save It After Modifying

Jun 21, 2014

I have to read a particular student data from file using his Roll no and modify it and then save it to file again

This is the File
24 salman 98 97 96 95 94 A ;
21 faizan 88 87 86 83 85 B ;
35 Gohar 99 98 97 96 90 B ;
45 sibghat 91 92 78 85 88 C ;
009 john 89 87 91 78 95 C ;

how can i read data of roll no 35 and modify it and save it again to the file

this is my program

int r = 0 ;
while ( ar[j]!="0" ) {
//cout << "Salman majid is
" ;
if ( ar[j]==k ) {
r = j ;
getdata() ;

[Code] .....

View 2 Replies View Related

C++ :: Read Data From A File - Show Max And Min From Scores

Feb 26, 2013

My program reads data from a txt file and it displays the test scores and the sum of the scores, and it also shows the max and min from the scores , so far only one number shows up from the scores instead 10 and i think my sum is wrong too, but i cant get the max and min to work ...

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void openfile(ifstream &infile);

[Code] .....

View 17 Replies View Related

C++ :: Read From A File And Place Data Into Array

May 3, 2014

Assume you want to read from a file and place the data from the file into an array. The array can hold 10 integers. The file may contain any number of integers with 1 integer per line. Fill in the missing loop test condition so that we will read from the file until either end of file occurs or the array is full. Note we are using cin to read from the file since input redirection is being used.

cin >> temp;
arrayIndex = 0;
while ( _____________________________________) {
array[arrayIndex] = temp;
arrayIndex++;
cin >> temp;
}

View 2 Replies View Related

C/C++ :: Read A Line With 8 Bytes Of Data From A File

Jul 23, 2012

How to read a line with maximum of 8 bytes from a line in a file.

Let say line has 10248 bytes in one single line and same repeats for remaining lines in the file.

I need to read the first 8 bytes of a line and go on read the last 2 bytes of the line and repeat the till end of file.

View 3 Replies View Related

C++ :: Access Violation When Using Pointers To Read Data

Apr 23, 2013

I have the following method to read in a data file using a struct and a doubly linked list.

The readFile method is as follows:

Code:
struct contact *readFile(char * FName,struct contact **ptrList) {
struct contact *head, *newContact;
FILE *fptr;
char oneLine[60];
char *sname, *fname, *phone,*company, *email;

[Code] .....

My struct definition is like this:

Code:
struct contact {
char sname[15];
char fname[15];
char phone[15];
char company[15];
char email[15];
struct contact *prev;
struct contact *next;
};

View 2 Replies View Related

C++ :: WHILE Loop Error / In Streaming Data File (with Functions)

Nov 2, 2014

I have a working lab project with a loop error. Code posted in second post. Here's the requirements:

*
- program has to be able to handle file failure
- must loop (prefer to use a while loop here), read in the data, calculates values, etc. and then output the results.

*
The input data file includes

1. a 1 or a 0 indicating that there is a set of employee data following

2. the hourly rate of the employee

3. the humber of hours worked

4. the number of dependents

5. a 1 or a 0 indicating whether the employee is full time (1=full time).

Problem: At first I wouldn't loop back... so I moved the curly brace above the return0;

View 2 Replies View Related

C# :: Add Data Grid View Column To Listbox Using For Loop

Apr 18, 2014

I need to take a single column and all the rows in the column from a datagridview to a listbox using a for loop. My code is giving me no errors just not showing any data in the listbox.

private void frmProject6_Load(object sender, EventArgs e) {
// TODO: This line of code loads data into the 'enrollmentsDataSet.Enrollments' table. You can move, or remove it, as needed.
this.enrollmentsTableAdapter.Fill(this.enrollmentsDataSet.Enrollments);

[Code] .....

View 1 Replies View Related







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