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
ADVERTISEMENT
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
Feb 16, 2013
I'm having an issue with output, luckily everything else works!! I'm working with Mixed Numbers and operations on them. So, here's the code I'm testing with:
int main() {
Mixed m1(5), m2(1,1,1), m5(2,2,3);
cout << "m1+m2= " << m1+m2 << endl;
cout << "m1 + 10=" << m1+10 << endl;
cout << "m1 - 10=" << m1-10 << endl;
return 0;
}
And here is the output for that code:
File name: fract.h
#ifndef fract_H
#define fract_H
#include <iostream>
using namespace std;
const int DEFAULT_VAL = 0;
[Code] ....
View 2 Replies
View Related
Feb 23, 2015
I'm reading in a string from the command line into a char array followed by a series of ints which are read into an int array.
The command line
Code: lab3 word word word 0 0 2 3 results in the following output:
Code: Word: .N=▒
Number of Words: 0
Word: .N=▒word word word
Number of Words: 3
Num: 0
Num: 0
Num: 2
Num: 3
Here is the source code:
int main(int argc, char *argv[]){
if(argc < 2){
//command line must have at least three arguments (one
//char, one integer)
printf("Error: invalid number of arguments
[Code] .....
Where is the .N=▒ coming from?
View 3 Replies
View Related
Nov 13, 2014
I'm trying to make a simple temperature converter with a menu that lets users pick which conversion to perform. But, it won't seem to print the right conversion. It just prints the same temperature that I inputted.
for example:
#include <iostream>
using namespace std;
//prints the menu
void userMenu(){
cout << "Temperature Calculator" << endl << endl;
[Code] .....
View 2 Replies
View Related
Apr 18, 2013
I have managed to make a program that permutates a string with repetition.
I ran it to permutate "abcdefghijklmnopqrstuvwxyz1234567890" with a limit of 5 characters.
This took a little over 5 hours for my pc to process this and I ended up with a .txt 403MB in size. Needless to say I am unable to open this .txt in notepad without Notepad.exe not responding and me having to end the process.
So what I want to do is modify my code to break up the output in to several files rather than one. Possibly all permutations starting with a in one file, b in another, etc.
Here is my current code:
#include <iostream>
#include <string>
#include <sstream>
[Code]....
As you can see it currently appends permutation.txt with all output. I would like it to make files like this permut_5char_a.txt, permut_5char_b.txt, etc.
View 12 Replies
View Related
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
View Related
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
Feb 12, 2013
I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)
_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60
When printed out, the names are formatted as follows:
lastname, firstname: 90
lname, fname: 100
last, first: 60
However, when I print them out this is what I get:
lastname, firstname: 90
lname, fname: 100$
last, first: 60H
For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.
Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {
[Code]......
View 6 Replies
View Related
Jun 18, 2014
The assignment is to plot the functions, by implementing a function having the following prototype:
void plotPoint(double y);
This function should print a single "*" symbol, in a position determined by the value of y, and then a newline. The position of the * symbol can span over 80 columns: each column should represent a delta of length 0.1 in the value of y, and the zero should be placed on the 40-th column.
For example:
• placePoint(0) should print the * symbol on the 40th column
• placePoint(0.1) should print the * symbol on the 41st column
• placePoint(1) should print the * symbol on the 50th column
• placePoint(-1) should print the * symbol on the 30th column
Here is what I have so far:
#include <iostream>
#include <cmath>
int a;
int b;
int x;
int y;
int Func1(double a, double b )/>
[Code] ....
I'm lost now as to where to go to plot. I know that depending on the option chosen I call the corresponding function to return a value for y which is just then plugged into a function to plot it on columns of y.
View 6 Replies
View Related
Nov 7, 2014
I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.
Example of the file being read
Code:
Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.
[Code] .....
View 14 Replies
View Related
Feb 20, 2013
I have 2 function (AddEntry & PrintEntry)
I don't understand why the "PrintEntry" function doesn't print the first element at "phonebook[x].Name".
Code:
int counter=0;
void AddEntry(phone phonebook[]) {
counter++;
printf("Enter first name:
");
scanf("%s",phonebook[counter-1].Name);
printf("Enter last name:
[Code]...
Code:
int main(void) {
phone phonebook[20];
int i;
for (i=0;i<4;i++) {
AddEntry(phonebook);
PrintEntry(phonebook);
}
return 0;
}
View 3 Replies
View Related
Apr 7, 2013
I am trying to solve the following task:
-Write a recursive function that prints an integer with decimal separators. For example, 12345678 should be printed as 12,345,678.
The problem is that I don't know how to modify the integer in such way. I was thinking to convert it into a string, do an algorithm and then turn the string back to integer.
How to do such modification.
View 9 Replies
View Related
Feb 8, 2014
I need c source that give the url txt file and print the txt file
(get the http://site.com/text.txt) and print the (text.txt) file Content.
View 1 Replies
View Related
Sep 13, 2013
The requirement is to capture statistics of uuid occurrences for ALIVE/SEARCH/BYEBYE (it can be all 3, combinations of 2 each, or one alone) in a dynamically populated file in run time.
I am able to print all 3 combinations, but not in combination of 1 or 2 e.g.
If my input.txt is like this :
uuid:22314754-a597-490b-8a93-02cfae01036b ALIVE 16
uuid:22314754-a597-490b-8a93-02cfae01036b BYEBYE 8
uuid:22314754-a597-490b-8a93-02cfae01036b SEARCH 8
uuid:50e65653-7525-485d-83bf-d293558c4264 ALIVE 32
uuid:50e65653-7525-485d-83bf-d293558c4264 BYEBYE 8
uuid:50e65653-7525-485d-83bf-d293558c4264 SEARCH 132
[Code]...
Code:
#include<stdio.h>
#include<string.h>
struct uid
{
char uid_val[100];
char state[100];
int temp_count;
int alive_count;
int search_count;
[Code]...
Gives the following output ->output.txt)
Device ID ALIVE BYEBYE SEARCH
uuid:22314754-a597-490b-8a93-02cfae01036b 16 8 8
uuid:50e65653-7525-485d-83bf-d293558c4264 32 8 132
uuid:55076f6e-6b79-4d65-6497-180373763bc1 113 112 111
uuid:T0100203354 1 2 3
I want to generalize the code such that uuid occurrence does not have to be all 3 (ALIVE/SEARCH/BYEBYE), the occurrences can be any combination and code should work. e.g my code gives wrong results when input.txt contains the following:
uuid:22314754-a597-490b-8a93-02cfae01036b BYEBYE 8
uuid:22314754-a597-490b-8a93-02cfae01036b SEARCH 8
uuid:50e65653-7525-485d-83bf-d293558c4264 ALIVE 32
uuid:50e65653-7525-485d-83bf-d293558c4264 BYEBYE 8
uuid:55076f6e-6b79-4d65-6497-180373763bc1 ALIVE 113
uuid:55076f6e-6b79-4d65-6497-180373763bc1 BYEBYE 112
uuid:55076f6e-6b79-4d65-6497-180373763bc1 SEARCH 111
uuid:T0100203354 BYEBYE 2
I am using ubuntu for gcc/g+ compiler.
View 1 Replies
View Related
Aug 10, 2014
I have a file with data in it, and I'm trying to print that data, but it is:
1) not reading the last file (record #83)
2) it's printing out the last record twice (in this case, #77)
//record data for each tool
int recordNumber;
string toolName;
int quantity;
[Code]....
here is the printData() function
void Hardware::printData(int _recordNumber, string _toolName, int _quantity, double _cost)
{
cout << left << setw(10) << getRecordNumber() << setw(20) << getToolName()
<< setw(10) << getQuantity() << right << setw(10) << fixed << setprecision(2) << getCost() << endl;
}
View 9 Replies
View Related
Aug 24, 2013
these are the errors that I'm getting from an online c++ compiler
// main.cpp:4:10: error: #include expects "FILENAME" or
// main.cpp: In function 'void permute(char*, int)':
// main.cpp:17:9: error: 'f' was not declared in this scope
I don't understand how to print full_string to a file!// otherwise, I know that it gives the correct output -- 90 strings.
#include <string>
#include <iostream>
#include <fstream>
#include >ios> // line 4 error
using namespace std;
char full_string[] = "112233";
[code]....
//iter_swap – it just swaps the elements pointed to by the respective pointers without changing the pointers themselves. so, it's basically equivalent to the function:
void iter_swap(char *ptr1, char *ptr2) {
char tmp = *ptr1; *ptr1 = *ptr2;
*ptr2 = tmp;
}
// min_element – finds the location of the minimum element that exists in the given range. in this case,
it is the char* pointer pointing to the location of that element. it can be implemented like:
char *min_element(char *start, char *end) {
// end is 1 beyond the last valid element
if(start == end) return end; // empty range
char *min_pos = start;
for(char *iter = start+1; iter != end; ++iter)
[code]....
View 7 Replies
View Related
Sep 4, 2012
I am encoding some information in a binary file, and I want to check what I am doing by printing out all the bytes that represent the file.
This is being done by opening a pointer to the file with fopen, reading in each byte of data as a char, and then writing this char to the screen.
I have some image files (e.g. "image.jpg"), whose structure I know, so that I can test my program.
When I print out the chars, they are initially correct, and follow the structure of the file as expected.
However, after about 40 bytes, I find that every subsequent character is ' ' i.e. a blank character.
I then created a CharToBin function, which allows me to print out the actual bits in the char. When doing this, it shows that all the bits are 1 for the characters. i.e. most of the file is represented by 1's, which is clearly not correct.
This happens on all the image files I have tested, and furthermore, on several other non-image files. They all start printing out ' ' after a while. However, all these files are fine and not corrupted, e.g. the image files display correctly.
Code:
#include <fstream>
#include <iostream>
#include <sstring>
#include <string>
#include <stdio.h>
using namespace std;
string CharToBin(char ch) {
bool bits[8];
for (int i = 0; i < 8; i++)
[Code] ....
View 6 Replies
View Related
Jun 27, 2013
I have done an exercise from "Thinking in C++" to print text from a file to the console one line at a time, with the user pressing enter to get the next line.
My original code is below, how could I change it for one word at a time?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
[Code] .....
I tried to alter my program to print one word at a time by changing "getline(in, word)" to "in >> word", but it prints each new word on a new line, the only input I have found to make the next word appear is Enter, I assume that's why.
Is there a way to make it print one word at a time when the user says, but on the same line?
View 4 Replies
View Related
Nov 14, 2013
I need to create a text file that looks like:
first line
second line
third line
forth line
fifth line
sixth line
I want to replace the third and forth lines with three new lines. The above contents would become:
first line
second line
new line1
new line2
new line3
fifth line
sixth line
How can I do this using c++?
never was taught file function in c++
View 3 Replies
View Related
Jun 5, 2014
void readpatient() {
int count = 0;
f = fopen("patient.txt","r");
while(!feof(f)) {
printf("
%d",count++);
p2=new patient();
[Code] .....
Here is what I've tried. I'm trying to read a file aND print stuff in it, but my while loop isn't ending up.. What should i do? It only prints patient name 1 time and after that it prints nothing.
removing system("pause");
results in an endless loop.
View 2 Replies
View Related
Feb 26, 2015
I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
[Code].....
It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.
View 1 Replies
View Related
Dec 1, 2013
I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.
I already read about strtol but I would prefer reading the hex Value into an integer.
Here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int itrack1[1];
int itrack2[1];
[Code] ....
View 11 Replies
View Related
Jan 14, 2014
I have 3 arrays (even, odd and negative), they are all different sizes, but they maximum elements they can have is 50. How do I write them to a file in this format
EVEN ODD NEGATIVE
2 3 -2
4 5 -4
6 7 -9
Code:
size = 50; //they dont all 50, its just that array cant be bigger than 50
for (int i =0; i < size; i++) {
cout <<setw(5);
if (even[i] != 0) {
myfile << eList[i];
myfile << endl;
[Code] .....
View 5 Replies
View Related
Dec 6, 2013
Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.
Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");
[Code] .....
View 6 Replies
View Related
Jan 2, 2015
I am trying to establish a connection between client and server to send a file to the server from a client. I have been successfully able to send files to the server but i am facing a problem with the the filename whenever i try to send any string to the server and use it in naming the filename at the server side, the string is successfully concatenated but it saves the filecontents in the filename.
for example: i am sending a file hello1.txt to server and the server has to save it as abcxyz.txt as i am sending the "xyz" from the client. BUT Whenever i am doing this ,the file saves as abcxyzfilecontents.txt If i saved in the .txt file "you123" ,my file at server side would save as abcxyzyou123.txt
Here are my codes:
Know that the server code implements a multi threaded server. The functionality to be discussed is defined in myfunc
Code:
server.c:
#include <stdlib.h>
#include <stdio.h>
[Code].....
View 1 Replies
View Related