Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to read everything from file redirection into a new file using C. Here is what I have: int main(int argc,char *argv[]) { FILE

I need to read everything from file redirection into a new file using C. Here is what I have:

int main(int argc,char *argv[]) { FILE *fp; char temp_filename[] = "out.sp19";

if(argc == 1) // execute for file redirect {

printf("Getting data from file redirect. ");

fp = fopen("out.sp19", "w"); //create temp file to store data from command line.

if(!fp) // validation to make sure out.sp19 is created. { printf("Error opening file."); return 0; }

fprintf (fp,"%s ", stdin); //Print arguments from redirect to fp. fclose(fp);

}

This program executes ok, but the file "out.sp19" is empty.

Assuming the following:

1) The executable is named test.exe

2)The file being redirected is called redirect.txt

3) redirect.txt contains: apple banana orange

From the command line the program is executed like so: test < redirect.txt

All the contents from redirect.txt should then be written to out.sp19, but I am getting and empty file. Please help get the given code working.

Thanks!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago