C/C++ :: Importing Data From TXT File And Working With It
Mar 13, 2013
This code will show the data from the .txt file "file1" the data is (0.0 0.1 0.2 0.5 0.8 0.9 1.0)
What I'm trying to do is take these float values and add them all up and divide them by 7 (finding the average and output that)
Convert it into a percent and print it in a field:
Width of 6 with 2 digits after the decimal point...
I tried doing something like cout << "the average is: " << data/7 << endl; but that didn't work. I got an error that said "/" was not an operator.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myfile("file1.txt");
string data;
getline (myfile, data);
cout << data << endl;
myfile.close();
return 0;
}
View 1 Replies
ADVERTISEMENT
Mar 13, 2013
This code will show the data from the .txt file "file1" the data is (0.0 0.1 0.2 0.5 0.8 0.9 1.0)
What I'm trying to do is take these float values and add them all up and divide them by 7 (finding the average and output that) Convert it into a percent and print it in a field:
Width of 6 with 2 digits after the decimal point...
I tried doing something like cout << "the average is: " << data/7 << endl; but that didn't work. I got an error that said "/" was not an operator.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myfile("file1.txt");
string data;
getline (myfile, data);
cout << data << endl;
myfile.close();
return 0;
}
View 1 Replies
View Related
Feb 27, 2014
i need my code to stop outputting all the numbers throughout the steps it is going through i just need it to output the total
this is my input
M
C
C
C
L
I
V
and its output is
Your total is 1000
Your total is 1100
Your total is 1200
Your total is 1300
your total is 1350
Your total is 1351
i just need it to output the last number
// write a program to read a string of characters
// that represent a Roman numberal and then convert
// to Arabic form ( an integer
// input from data file
[Code].....
View 1 Replies
View Related
Sep 13, 2013
I am trying to enter data to a structure some 8 times, but not able to do so. Here is my code.
Code: #include<stdio.h>
struct _Timer {
unsigned int HH;
unsigned int MM;
}Time[8];
[code]...
But when I enter any data and press enter , the .exe file stops working and not able to enter data.
View 4 Replies
View Related
Nov 21, 2013
I am trying to take a Text File mydata.txt and import it into a structure however when I try to run this code it just closes out.
Code:
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<ctype.h>
struct hard_disk{
char name[18];
double size;
[Code] .....
View 4 Replies
View Related
Mar 1, 2013
private String[] GetExcelSheetNames(string excelFile) {
OleDbConnection objConn = null;
SqlConnection objSqlConn = null;
System.Data.DataTable dt = null;
try {
[code].....
Now I can fatch all the excel sheet belongs to the Excel File.But How can I check "If and Only If the sheets are havin Underscore in their name(eg. student_data,teachers_data) then only the data of the sheets will populate in tha data base"
View 2 Replies
View Related
Dec 17, 2013
I have the following code and I am trying to do simple math calculations to the data. I need to take the car price (y) minus down payment (z) and then divide that quantity by 12 times "yearsx" That answer is then assigned to x. The problem is that x will not print the correctly!I also noticed that if I increase the "count" to amnything higher than the number on lines in the file, I get the correct value for x but only on the last set of the struct..my file reads as follows:
last_name first_name car_price down_payment years
johnson bill 10,000 2,000 3
When I printf the struct to the screen, i need to do the following:
x = (10,000 - 2,000)/(12*years);
but this is the math part that wont work. I have checked and doubled checked number types and I cant get it right.
Code:
#include<stdio.h>
#include<stdlib.h>
#define FILENAME "file.txt"
#define SIZE 100
}
[code]....
View 3 Replies
View Related
Jun 24, 2013
Code:
/* some useful headers */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
//my headers
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
[XCode] .....
The bit that's giving me issues is the "calculatedetails" function, where an mp3 file is opened in binary and then an array of chars is filled with the binary data.
The problem I'm having is that I want to be able to read the constituent bits of the characters in, so that I can find the mp3 frame headers (12 1's in succession)
I'm aware that the section I've added in to perform this is incorrect.
View 7 Replies
View Related
Feb 22, 2015
I already have this but I sense I'm missing something so I'd like to be pointed to a proper article/document on this sorta thing.
Code:
#if defined( __GNUC__ ) || defined( __GNUP__ )
#define PP_ATTR( TYPE ) __attribute__( TYPE )
#ifndef _PRAGMA
#define _PRAGMA( COMMAND ) _Pragma( #COMMAND )
[Code] .....
View 12 Replies
View Related
Oct 2, 2012
how do I import the stripped export names (no mangling) from C code
A functions int Func()
is exported by def file to MyDll.dll
LIBRARY
EXPORTS
Func
Now if I import from another source Func by providing
exyern "C" int Func()
/lib:MyDll.lib
I get error error LNK2019: unresolved external symbol Func referenced in function main
View 1 Replies
View Related
Nov 9, 2014
Essentially what I need to do is take a text file, ("input.txt"):
4 4
1 0 0 1
1 1 1 1
0 0 1 0
0 0 1 0
And take the first two values on line 1 (4, 4) and use them as length and width.
Number of rows: 4
Number of columns: 4
Then I need to print out the matrix and further manipulate it. I need to find the sum of the 1's per column and then take that number and replace each 1 with the 1's in each column.
So it'll look like this:
2 0 0 2
2 1 3 2
0 0 3 0
0 0 3 0
The part that's mostly troubling me is that my instructor will be giving me the input file with random values, so I don't know what the matrix dimensions will be.
I can read the 2D array but can't seem to use it after. I need to find a way to skip the first line, and then read in the matrix and be able to use it mathematically to add up each column.
View 1 Replies
View Related
Mar 29, 2013
I'm trying to add a function now that lets the user open 1 or more files and import them to the database and dataGridView. Now the way it is now (should) work. But when it has finished with FILE1, it won't add FILE2 as it then gives me an error that the Column Date Already exists.
My code is below
private void btnOpenLog_Click(object sender, EventArgs e) {
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Log Files (*.log)|*.log";
openFileDialog1.Multiselect = true;
[Code] .....
View 12 Replies
View Related
Oct 28, 2014
I am trying to write my files to another subfolder . Below is my program.
Code:
cat th6.c
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#define SIZE 8
#define NUMELM 8
[Code] ....
I observe my filename along with directory as text in the new file created in sublfolder. This is output.
[cporgs/apue/threads]: mkdir first
[cporgs/apue/threads]: ./a.out test.txt first
test.txt -- first/test.txt
dfdfdfdfdfdfdf-14
dfdfdfdfdfdfdf-14
in thread test.txt first
[cporgs/apue/threads]: cat first/test.txt
dfdfdfdfdfdfdffirst/test.txt
[cporgs/apue/threads]: cat test.txt
dfdfdfdfdfdfdf
I could not able to get from where this filename and folder is getting added.
View 4 Replies
View Related
Sep 2, 2014
I need to append file path for some particular program. But the problem is when I append it like below, it gets error whether filepath seems to be C:/Users/My/Desktop/C++/1.txt
int i=1;
stringstream str;
str<<"C:/Users/My/Desktop/C++/"<<i<<".txt";
string filepath=str.str();
cout<<filepath;
ifstream ipf(filepath);
if(ipf)
{ do some thing...}
But if it was like this no error, program work as desired.
int i=1;
stringstream str;
str<<"C:/Users/My/Desktop/C++/"<<i<<".txt";
string filepath=str.str();
cout<<filepath;
ifstream ipf("C:/Users/My/Desktop/C++/1.txt");
if(ipf)
{ do some thing...}
View 7 Replies
View Related
Mar 27, 2013
I would like to modify attributes like modification/creation dates.The function is correctly working as if I type in "ls -al", the timestamp is correct. But when using my program to read these attributes, it returns the "real" modification/creation date. Here is the function that shows the timestamp :
Code:
time_t t = sb.st_mtime; struct tm tm = *localtime (&t);
char s[32];
strftime (s, sizeof s, "%d/%m/%Y %H:%M:%S", &tm);
printf ("%-14s %s", lecture->d_name, s); And here is the code for modifying the timestamps : Code: void modifyAttributes(char * file, int mtime, int atime)
}
[code]....
View 9 Replies
View Related
Jan 11, 2015
I am trying to take text from a file and have it displayed using fprintf at line 46. When I run the below code nothing prints out. My text file has 4 lines with 5 different strings separated by whitespace.
#include <cstdlib>
#include <vector>
#include <cstring>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
using namespace std;
//declare my own struct
[Code]...
View 7 Replies
View Related
Dec 6, 2013
i have turbo c++ 3.0 installed . my program is compiled without error and is running. but when i choose option to display scores in the consol , it hangs . check my code. i have to run this on same compiler. i just want to display all the contenets of text file .
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
[Code].....
View 4 Replies
View Related
Mar 24, 2013
Why my output screen for this program does not want to stay open. It only opens for a split of a second and it's gone. The program is supposed to take numbers from a input file and display and save the manipulation in the output file. Here is the program.
Code:
#include<iostream>
#include<fstream>
#include<iomanip>
usingnamespace std;
[Code] ....
View 6 Replies
View Related
Dec 17, 2013
I have to write a program (on linux) which will count character, words and lines like wc linux command. I'm trying to write this for last 3 days... First part of app I did and it works fine - command line options to choose. Then I've got a function read_file which I have to use to read a file. One of the options is to get the file name from user and if user will not type any name then the standard file is ubuntu dict file /usr/share/dict/words, this is not working as well...
Counting characters and lines is working fine but because I don't know how to get text from read_file wrote code to read file interior this functions. Words counting is working partly - everything is fine until there are two or more spaces, tabs one after another then counts extra words. Finally I need child processes in words and lines counting functions. Parent process should waits for all childs to finish and should be pipes to submit character counts back to parent process. How to do all this things with processes...
Code:
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/*size of character buffer to read in a file. */
#define BUFFSIZE 1000000
[code]....
View 2 Replies
View Related
Apr 28, 2014
I know how to open a specific files by using
ifstream infile("something.txt");
but how do you let the user select an arbitrary file from the working directory?
View 12 Replies
View Related
Mar 8, 2013
Ben has been administering a MBTI personality test. Now he has all the responses, but the task of scoring and compiling results seems daunting. The personality test* is a series of 70 questions for which the available responses are ‘A’ and ‘B’. Based upon the answers to the 70 questions, a personality profile is determined, categorizing the degree to which the responses place the person on four scales:
Extrovert vs. Introvert (E/I)
Sensation vs. iNtuition (S/N)
Thinking vs. Feeling (T/F)
Judging vs. Perceiving (J/P).
Each of the 70 questions relates to one of the four scales, with an ‘A’ response indicating the first of the corresponding pair (E, S, T, or J) and a ‘B’ indicating the second (I, N, F, or P). For instance, an ‘A’ response on the question: At a party do you:
A. Interact with many, including strangers
B. Interact with a few, known to you indicates an Extrovert rather than an Introvert; just the opposite for a ‘B’.
For this test, each question is designed to influence one of the four scales as follows:
questions 1, 8, 15, 22, 29 … are used to determine E/I,
questions 2, 9, 16, 23, 30 … and 3, 10, 17, 24, 31 … to determine S/N,
questions 4, 11, 18, 25, 32 … and 5, 12, 19, 26, 33 … to determine T/F, and
questions 6, 13, 20, 27, 34 … and 7, 14, 21, 28, 35 … to determine J/P.
Notice these come in sequences of “every 7th” question.
The goal of the test is to determine which end of each of the four scales a person leans, and to thus classify him/her based on those leanings (e.g., as ENFJ, INTJ, etc.). Since Ben would also like an indication of how strongly the test taker fell into each of the four, the program should print the percentage of ‘A’ responses for that scale.
Input for this program should come from a file responses.txt. The first line of the file will contain a single integer, n, indicating the number of test results to follow. Each of the following n lines will contain the first name of the test taker, a single blank, his/her last name, a single blank, then the 70 responses he/she gave on the test. Although the test instructions indicate that the results are most valid when all questions are answered, sometimes respondents leave questions blank. In that case, a dash appears at the corresponding place in the list of responses.
Output for the program should be written to the file types.txt. It should include a well-formatted report listing, for each test taker, his/her name, the percentage of ‘A’ responses in each scale, and the resulting personality type. A tie within a scale should result in a dash (‘-‘) for that part of the personality type.
View 2 Replies
View Related
Aug 23, 2012
I am trying to stream data to a file, and then return to the file to add further data. When I add data the second time, I then want to update the value of the second byte in the whole file. I can't seem to do this!
Here is my sample code:
Code:
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int x;
fstream out1("file.dat", ios::out | ios::binary | ios::trunc);
[code]....
The output I get is "1, 2, 3, 4, 5, 6", but I want to be getting "1, 7, 3, 4, 5, 6", because in "out2", I seekp to the second integar entry, and change it to "7".
I have also tried using ios::ate in the constructor for "out2", but this gives me the out put "4, 7, 6, 6, 6, 6", which is suggesting that when I create my fstream object "in", any seekg commands are relative to the beginning of the "out2" stream, rather than the "out1" stream.
View 3 Replies
View Related
Dec 6, 2013
I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.
Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();
[Code] ....
View 4 Replies
View Related
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
Mar 28, 2015
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.
MY task is to write a program that does the following things:
1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.
2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.
3. Prompt the use for their height (in inches) and their weight.
4. Make the program print the closest BMI.
If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.
5.Loop the program so the user can find more BMI’s.
View 7 Replies
View Related
Jan 11, 2014
I'm reading from a file the middle column of data (Volts) where my test file "AP.txt" is opened by my program. Here is a segment of the data:
time Volts dV
49552 -66.20183 -0.01556807
49553 -67.76025 -0.01556495
49554 -69.30704 -0.01533247
49555 -70.81799 -0.0148486
49556 -72.26774 -0.0141133
49557 -73.63226 -0.01315276
49558 -74.89141 -0.01201764
Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.
Here is my program so far:
int main()
{
std::ifstream inFile;
inFile.open("AP.txt");
ofstream results_file ("maxvaluewithinput.txt");
float TimeAtdVMax = 0;
float VoltsAtdVmax = 0;
[Code]...
If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.
View 10 Replies
View Related