C++ :: How To Output Void Function On A Text File

Feb 12, 2013

So I am writing this code that analyzes a file called "analysis.txt" and prints out in an ouput file (called "report.txt") the results of the analysis, i.e.,(the frequency of all alphabet letters present in the file).

I am having trouble with outputing on the file2.

here is what I have:

Code:

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

[Code]....

I tried to lose the "<<" after the file 2, but it's still giving me an error. how to output a void function on a text file?

View 14 Replies


ADVERTISEMENT

C++ :: Opening A File In Void Function

Feb 26, 2013

how do you open a file inside of a void function

this is the code i have

#include <iostream>
#include <fstream>
#include <sstream>

[Code]....

View 6 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++ ::  Why Every First Function Of Each File Get Error - Multiple Definition Of Void Pointer

May 6, 2014

I declared all functions in header file, such as:

bool readCase();

bool meshing();
bool readMesh();

bool calculateFlowfield();
bool readFlowfield();

bool calculateEvaporation();

And then I define them in separated .cpp files, each .cpp file include the header, but I got multiple definition error, why?

Even the int main() function, which only decalred and defined once got this error, why?

View 14 Replies View Related

C :: Output Does Not Print On Text File

Jul 19, 2013

In this program I can not print the typed value in the file. The file creation well done but it is an empty file

I press Ctrl +z for EOF

Code:
#include<stdio.h>
int main(void){
FILE *fp;
char ch;
fp=fopen(" Test.txt","w");
printf(" Enter the TEXT

[Code] .....

View 1 Replies View Related

C++ :: Program Won't Output Any Information To Text File

May 6, 2013

my program wont output any information to the text file that I have specified it just creates it but it leaves it blank

#include <iostream>
#include<string>
#include<iomanip>
#include <fstream>
using namespace std;
class Carloan

[code]....

View 2 Replies View Related

C++ :: Output Unusual Format For Text File

Jul 24, 2013

Bit of a problem, I'm trying to output the data from my code into a particular format to a text file. The format is

y0 y1 y2 y3 y4 y5...yn
z0 0.01 0.2 1
z1 0.4 0 etc...
z2
z3
z4
z5
...
zn

Any pointers?

View 1 Replies View Related

C++ :: Writing Output Of While Loop To Text File?

Jul 30, 2014

[URL] when I try to write my output to a file. I am building a life insurance premium calculator with c++. What my calculator does is read in a text file called "policies.txt" containing a number of different policies. For example:

Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99

And using this, it creates a single premium. Once the calculator calculates the premium of each policy, I want it to write out the premium amount of each policy to a textfile called "output.txt". The problem is that when I check my "output.txt" file, only the premium for the last policy shows up. It only reads:

Premium for Pol4 is 220384
When I want it to read:

Premium for Pol1 is 14101.6
Premium for Pol2 is 14221.2
Premium for Pol3 is 582391
Premium for Pol4 is 220384

How come only the last policy is showing up? and is there any way to make all four policies appear in my output text file? Here is my code:

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};

[Code]....

View 2 Replies View Related

C++ :: Getting 2 Decimal Places In Output Text File?

Jul 30, 2014

how I can make my output only have 2 decimal places because I want it to be a monetary value. In my code I used this:

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

which worked well at first because on my command prompt screen the numbers had two decimal places and looked liked this:

Premium for Pol1 is $14101.62
Premium for Pol2 is $14221.16
Premium for Pol3 is $582390.50
Premium for Pol4 is $220384.49

However, I also have the program outputting to a textfile called "output.txt" and when I opened this text file the numbers only had one or no decimal places.

Premium for Pol1 is $14101.6
Premium for Pol2 is $14221.2
Premium for Pol3 is $582391
Premium for Pol4 is $220384

How come the code for two decimal places is working for my output to command prompt but not my output to the text file?

Here is my code.

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};

[Code].....

View 2 Replies View Related

C/C++ :: Read Text File And Display It In Output

Apr 7, 2014

I'm supposed to read a text file and display it in the output. I have it down except my formatting. I just cannot get it to just skip one line rather than multiple. I know why though because my char has a max of 11 and if I put a character lets say mango, it is going to fill in the rest with white spaces. It's supposed to display like this:

Mango
Strawberry
Grapes

But instead I get something like this

Mango

Melon

Grapes

I am using isspace but it's not working.

//source code

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <fstream>
using namespace std;
class CFile

[Code] ....

View 5 Replies View Related

C++ :: Input / Output Text File Manipulation Not Working

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

C++ :: Grade Calculator - Output With Comment To A Text File

Feb 24, 2013

I am a math teacher who is taking a programming class. My district wants to incorporate some programming tasks into the high school math curricula. I am working on a project to calculate a final grade and output this along with a comment to a text file. The following data is the input that I created:

3 300 100 100 100 .15
4 400 100 98 94 92 .45
3 300 98 100 92 .40

The final grade output results in gibberish.

#include <iostream>
#include <fstream> // For file I/O
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

[Code] ....

View 6 Replies View Related

C/C++ :: Read All Song Titles From A Text File - Randomly Select And Output?

Apr 19, 2015

So far I have managed to sort songs by their string length in main. The void function is there because i learned how to create it, but it's not being used because I dont know how to use it.

Expanding on main, how would I go about selecting a random song from the array?

#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
struct Song {
string song;

[code]....

View 2 Replies View Related

C++ :: Multiple Of CSV File Used As Input / Extracting Data To A Output File - Getline Function

Jun 4, 2013

I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.

I run getline(inFile,line);
outFile << line << endl;

I run this code, and only part of it is goes to the output file I got, also have spacing randomly to specific file and inconsistent

But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....

Is my program running to fast, why getline would be skipping part of what things I want?

View 11 Replies View Related

C++ :: Printing Function Output To A File?

Oct 11, 2013

I have to convert a binary value from an input file (the name of which is given by the user) and then convert the binary to decimal value and print that in an output file.

Right now it is compiling just fine with no error messages, but when I run the program, it doesn't end or print to the output file.

Here is my code at the moment:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>

[Code].....

View 2 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

View 6 Replies View Related

C++ :: Passing A File Pointer To A Function Is Producing Undesired Output

Oct 27, 2013

I am working on a project and decided to try something simple before I start adding items. I am calling a function from main and that function has a file pointer.

Here is my main.cpp

Code: #include <cstdio>
#include <string>
#include <iostream>
#include "main.h"
extern FILE *fp;
using namespace std;
int main(int argc, char *argv[])

[code]....

Here is the function:

Code:
#include <string>
#include <cstdio>
#include <iostream>
#include "main.h"

[Code] ....

My test file consists of several characters and digits. Nothing special and I at this point in time do not have any type of formatting that needs to be adhered to. I am simply wanting to read the file character by character and print it out. When I run the program, I get this symbol:

Code: If I use a printf statement, such as:
Code: printf("%s
", nextChar);

I get a segmentation fault.

My main.h Code:

#ifndef MAIN_H
#define MAIN_H
void scanner(FILE *);
//char getChar(FILE *);
#endif and lastly my scanner.h Code: #ifndef SCANNER_H
#define SCANNER_H
FILE *fp;
#endif

View 6 Replies View Related

C++ :: Void As Function Argument

Mar 24, 2014

I was reading about void as function argument, but I did not fully understand it's meaning in C.

In C++
void foo(void) {}
and
void foo() {}

are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means

In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?

For example.

void foo() {
printf("%d", var);
}
foo(5);

It is very unclear for me. Do this apply to main function too?

int main(void)
int main()

or can I use arguments given to int main() like given to int main(int argc, char* argv[])

View 4 Replies View Related

C++ :: Using Break In Void Function That Does Not Contain A Loop

Jan 14, 2015

I need this break in my main function, but I'm not allowed to put it in void since void is not located in a loop. How can I solve this?

Code:
#include <iostream>#include <string>
using namespace std;
void login(string x, string y);
string username;
string password;
string x;
string y;

[Code] ....

View 6 Replies View Related

C++ :: Multiplication Table In A Void Function?

Jan 20, 2015

I wanted to make a multiplication table.

Here's the code:

#include<iostream>
#include<conio.h>
using namespace std;
void initArray(int arg1[50][50], int r, int c) {
int val=1;
for(int row=0; row<r; row++) {

[code]....

I want the output to be like this:

1 2 3
2 4 6
3 6 9

If the user inputs 3 rows and 3 columns.

View 5 Replies View Related

C :: Program To Use Void Pointers In A Function

May 14, 2014

As part of my ongoing c programming education, I have written a program to use void pointers in a function,

Code:

#include <stdio.h>
#define MAX_NUMBERS 10
size_t size(void *object);
int main(void) {
}

[code]....

Now I think that the result 4 is the size of the pointer, so I'm confussed as why it doesn't give me the same result as 40.

View 2 Replies View Related

C++ :: If Statement - Void Function Not Calling

Nov 2, 2013

I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.

#include<iostream>
#include<fstream>
using namespace std;
void bubbleSort();
void selectionSort();

[Code] .....

View 1 Replies View Related

C++ :: Void Function To Calculate Payroll

Dec 9, 2014

The purpose of this code is to calculate a pagecheck for intered hours and overtime for any hours over 40! This is what I have so far!

#include<iostream>
using namespace std;
void Amount (int hours, int wage, int sum);
void printCheck(int sum);
int main()

[code]....

View 1 Replies View Related

C++ :: How To Pass Char To Function Void

Jun 1, 2013

How to pass the char something[8][8] for example to function void ( char pass.....)???

View 7 Replies View Related

C++ :: How To Pass A Void Function As Parameter

Oct 20, 2013

How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.

In my Class:

void Utility::someFunction(int var1, int var2, void customFunction) {
int num1 = var1;
int num2 = var2;

[Code] .....

View 9 Replies View Related

C++ :: Using A Void Function For Data Input?

Feb 20, 2014

Modifying this program to Create a function that has the following prototype: void getInputChar(string, char &);.

The function should display the string on the screen and then use cin to read a char from the keyboard.

#include <iostream>
using namespace std;
bool ignoreCaseCompare (char, char);

[Code].....

View 1 Replies View Related







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