C :: Redirecting Output To A File
Jan 16, 2014
i am writing a c program, that sets up serial communication with my modem. The program works so far but i want the output to be redirected in a .txt or .csv file.
Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
[Code]....
View 2 Replies
ADVERTISEMENT
Sep 14, 2013
I have this code:
Code:
#include <stdio.h> //printf
#include <stdlib.h> //exit
#include <unistd.h> //fork
#include <sys/types.h> //pid_t
#include <sys/wait.h> //waitpid
}
[code]....
I would like to, when running cat, send in some data like "testing" to its stdin, and then catch the output of stdout, and put it into a character array variable.Currently the parent stalls till the child is done.I imagine the parent has to some how detect that the child executed 'cat', and then send in input to stdin?Then somehow detect that 'cat' is done executing, and read the output from stdout? I have looked around and found "dup2", but I don't understand how to send in and get data to the child from the parent, especially since the "file descriptors" is not pointing to any files in the first place..
View 4 Replies
View Related
Sep 20, 2013
Let us assume I have a program that takes the name of the output file from the command line. Now let us assume that a decided not to give any output file location but wanted my program to to print my strings/ints ... directly to stdout. how would one do this using file streams? Using file pointers and c that is pretty straight forward but how would i achieve this in c++.
View 12 Replies
View Related
Feb 3, 2015
I want to build a proxy, middleman between various client programs on my machine and servers outside, like this:
Client -> Proxy -> Server, Client <- Proxy <- Server.
OSes are Windows XP, 7 and 8.
Within that proxy I want to analyze data before it reaches it's destination and have full control over it to the point where I can prevent a packet from reaching it's destination if my program finds something suspisious going on. I need incoming and outgoing traffic of specific adresses and ports to be forwarded into my application on my client machine. My app then should deliver packets to their destination after they were analyzed.
The parts where data is received, analyzed, manipulated if needed, and sent is something I could code with no difficulty. But the concept of redirecting and forwarding is hard for me to grasp at the moment. I'd like to know at least what winsock functions I have to use.
If it's possible, I would like to use Windows libraries only, nothing from 3rd parties.
View 3 Replies
View Related
Mar 21, 2014
I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.
Code:
int main(int argc, char* argv[]){
char** cmd;
int Number_cmd;
cmd = &(argv[2]); /*list of cmds*/
Number_cmd = argc-2; /*number of cmds*/
}
[code]....
The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns
wc: standard input: Bad file descriptor
wc: -: Bad file descriptor
0 0 0
View 2 Replies
View Related
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
Aug 29, 2014
One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows:
John K. 99, 87, 57, 89, 90, 95
Amanda B. Jones 100, 88, 76, 99, 86, 92
etc..
The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the last (2) at 30% each.
Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
[Code]....
View 2 Replies
View Related
Aug 31, 2014
One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows: John K. 99, 87, 57, 89, 90, 95 Amanda B. Jones 100, 88, 76, 99, 86, 92 etc.. The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the next (2) at 15% each and the final at 30%. Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:
Code:
//
// main.c
// Final Exam
//
[Code].....
The problem I'm having now is how to go about passing the grades to the function computeGrade and then compute the average and return that to the function.
View 4 Replies
View Related
Jul 8, 2013
how do i decompress an input file and write the results into an output file?
also my do while loop is supposed to keep going unless the user selects the option to exit the program, instead it exits after finishing ay of the options.
here's my code so far...
#include <iostream>
#include <iomanip>
#include <fstream>
[Code]....
View 1 Replies
View Related
Sep 7, 2013
I have a program where I will read in a certain .txt file, such as "financial_data.txt" and I will be doing some sorting with this data.
I want my program to write out the sorted data to an output file and I want the name of the output file to be based off of the input name. For example, since my input file is "financial_data.txt", I want the output file name to be "financial_data_out.txt".
I am having a hard time finding examples online and in my reference manuals...
View 4 Replies
View Related
Mar 11, 2013
I have written this code to remove the comments from an input file and then put it into an output file. The program compiles and runs but it removes the whole line of code when it encounters a /* */ type comment. I believe the problem is in the while loop but I just don't know where.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(void) {
string infile, outfile;
ifstream source;
ofstream target;
[Code]...
View 3 Replies
View Related
Mar 25, 2013
I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml . They are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.
View 1 Replies
View Related
Mar 25, 2013
I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml .they are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.
View 1 Replies
View Related
Apr 20, 2014
I know this is how you read from a file. I also want to print my output to the same name of the file plus ".txt". So if my file is called "text" I want to print it to a file called "text.txt".
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
[Code]....
Would it be something like this? Is it better to use "a" or "w" in the fopen? I want to write to it several times.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
[Code].....
View 2 Replies
View Related
Aug 20, 2014
So I have a .txt file with, Name >> Username >> password >> adminstatus. It is filled with various names. for e.g.
Bob bobby bob123 1
tim timmy tim123 1
rit ritty rit123 0
john johnny john123 0
mary maryy mary123 mary 1
1 will represent admin in the program and 0 will represent a normal user. I want to make part of the program do something like this. > If adminstatus = 1, discount rate =3%. The thing is I will be using UDF to do so and I am unsure of how I am going to read for each user. What I mean by this is. If tim logins, how do I read ONLY tims line's admin status.
Currently I have a Login UDF. for that UDF I return something I named Loginstatus. If the login status = 1 . It will run the current problem that I'm trying to solve which is displaying the user adminstatus's discount rate. So how am I suppose to display the line of the user that logged in.
Here is the simplified explanation of my program. The user will login ( the program will see if everything matches up[username/password] then return loginstatus =1 if the user login successfully) Once the user logs in the program will bring up a menu which will have 2 options.
1. it will let the user check it's current discount rate.
2. quit.
View 2 Replies
View Related
Oct 8, 2014
How do you make a program output a ppm file?
Code:
#include <stdio.h>
void make_pixel
(
int r, // red intensity
[Code].....
View 7 Replies
View Related
Apr 4, 2013
I have 18,000 lines of code that i would like to upgrade to include a log file. I want to replace the cout with a stream or something similar so that i can easily output to the console and to a log file at the same time with minimal change to 18,000 lines of code. I'm nearly there.
I used this post heavily as a reference; [URL] .... however it is highly incomplete and this is above my knowledge so I'm struggling somewhat.
I was able to get the bulk of it working with some guess work and modification to the code from that link.
For some reason i had to comment out "mstream(void);" and "~mstream(void);"
Also how to get :
mstream& operator<< (ostream& (*pfun)(ostream&)) {
pfun(coss);
pfun(cout);
return *this;
}
to work for endl as per the previous link. Not sure if i'm even putting it in the right place. Otherwise the code works fine for streaming to both locations and such. See the code below;
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class mstream {
[Code] ....
View 9 Replies
View Related
Dec 30, 2013
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
#include<graphics.h>
void input();
void output ();
[Code] ....
View 1 Replies
View Related
Dec 10, 2014
I am trying to get my program to output the name from a file. The user should enter first name "or" last name. and if the user does not type the name from the input file. the get an error message. How do you do it
#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 4 Replies
View Related
Apr 2, 2014
Here is program I have written which reads the destination, then finds it from a separate file, and reserves the information on a different file. But the reserved file has hex code information, how can I output my result to the file in normal alphabet/number/symbol characters? I've tried fputs,fprintf, and fwrite , and all give me the same result. The array c, is the one to be written to file.
void main {
FILE *afile = fopen("flightrecord.txt","r");
int i=0,j=0,k=0,z=0,y=0,sum=0,seat=0,g=0;
char destination[10],a[1000],c[1000],b[1000],name[100],last_name[100],c_number[15],plane[]={'P','6','2'};
printf("What is your destination?");
scanf("%s",&destination);
[Code] ....
View 14 Replies
View Related
Jul 17, 2013
How to structure the input of one .dat file and outputting into another one. I have to loop through a file structured "doe, john, 1500", check for errors and then increase the mp by 50. You also have to do this through using a person class too. I think I need to use a while loop to go to eof and use getline to input correctly, but im not sure how to structure it.
Data file:
Horowitz,Jake,1200.24
Flabitz,Bubba,1712.38
Blackwell,Sharon,1872.93
Molerat,Rufus,501.00
Goodall,Jane,1567.43
Sommerset,William,1359.57
[Code] ......
View 4 Replies
View Related
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
Feb 7, 2013
Book database. I use scanf to store book name,author name and year when is book written. Example:
Code:
scanf(" %[^
]",k[i].bookname);
I have problem when i want to printf all books from database with this:
Code:
for(i=0;i<counter;i++){
fscanf(f,"%s %s %d",k[i].bookname,k[i].author,&k[i].year);
printf("
%d %s %s %d",(i+1),k[i].bookname,k[i].author,k[i].year);} Output:
Number Book name Author name Year
1 King John 0
2 William Shakespeare 1590
How can i fix this?
View 4 Replies
View Related
Feb 21, 2015
My project involves writing a c program to generate a set of 70 decimal numbers. I want to save the output (these 70 numbers) as a txt file. I tried the following:
1. prt scr of output screen and pasting it in notepad. NOT WORKING
2. going to DOS SHELL and doing the following:
c:TCBIN>output.exe>>output.txt
NOT WORKING. Text file is generated, but it does not contain output. It just says:
illegal command: output.exe
What do I do?
View 2 Replies
View Related
Apr 24, 2013
//code
ofstream outFile;
outFile.open("p4a.dat");
outFile << setw(8) << "90.0";
outFile << setw(8) << "75.0";
outFile << setw(8) << "36" << endl;
[Code] .....
View 1 Replies
View Related
Aug 8, 2014
I am currently doing a complex number calculator ,and i wish to output my data to a txt.file . i tried fstream and it doesnt work. However the txt.file was created but no text was output.
Below is the program:
#include<iomanip>
#include<cmath>
#include<iostream>
#include<fstream>
using namespace std;
#define PI 3.14159265358979323
double z,x;
[Code]..
When impedance A & B are in series,the effective Impedance is " <<setprecision(4)<< z << " + j" <<setprecision(3)<< x<<endl;
else
cout << "
When impedance A & B are in series,the effective Impedance is " <<setprecision(4)<<z << " - j" <<setprecision(3)<< x*(-1)<<endl;
}
void Complex::showdiv(double &z,double &x) {
if ( x>= 0 )
cout << "
When impedance A & B are in parallel,the effective Impedance is " <<setprecision(4)<< z << " + j" <<setprecision(3)<< x <<endl;
else
cout << "
When impedance A & B are in parallel,the effective Impedance is " <<setprecision(4)<<z << " - j" <<setprecision(3)<< x*(-1) <<endl;
}
class Polar:public Complex //inheritant from class Complex
{
protected:
double r,d,r2,d2;
public:
void PolarValue();
void ShowPolar();
[Code]...
View 6 Replies
View Related