Questions tagged [freopen]

freopen reopens a stream with a different file or mode.

Reuses stream to either open the file specified by filename or to change its access mode.

Reference: freopen

105 questions
0
votes
1 answer

freopen() does not read / write to existing file, niether creates new file in vscode

I am trying to read input and output from two separate text files in C++. Code(test.cpp): #include using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); …
Vishwas
  • 11
  • 2
0
votes
2 answers

Want to write in stdout after closing the file opened using freopen

I'm using fork(). However, before executing fork(), I open a file (say a.txt) using freopen for writing. Now the child process redirects the output of execlp to a.txt. After terminating the child process, the parent process closes a.txt. Now how…
miraj
  • 493
  • 2
  • 6
  • 7
0
votes
4 answers

freopen() creates a file when given an invalid path

I have a program that gets two paths as command line arguments. The first argument (actually the second, as the first one is the command name itself) is the path to the file the program reads from (input file). The second one is the path to the file…
avivgood2
  • 227
  • 3
  • 19
0
votes
0 answers

freopen() not able to write to a file?

On MacOSX, I'm trying to read input from inp.txt and write output to outp.txt on Sublime. I'm redirecting stdout to outp.txt #include using namespace std; int main(){ #ifndef ONLINE_JUDGE // for getting input from input.txt …
Sarat
  • 3
  • 3
0
votes
1 answer

How to detect end-of-file when using freopen in C++?

There's feof for fopen. But I am using freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); What is the equivalent of feof for this?
Casio991ms
  • 37
  • 8
0
votes
3 answers

Read Multiple Files In C++

I am trying to read two files "ListEmployees01.txt" and "ListEmployees02.table". But the program reads only the "ListEmployees01.txt" file and cout is just from that file. #define _CRT_SECURE_NO_WARNINGS #include #include using…
Duong Phan
  • 301
  • 5
  • 12
0
votes
2 answers

read whole of each line with different column

I have a text file like this: 1 2 3 4 5 6 7 8 just with money we can live 2 5 with this piece of code, I can show whole it on screen, but I cannot put it in a string, and its compile gives error : string test =""; string line2; freopen("a.txt",…
user12034867
0
votes
2 answers

Giving freopen() and stderr a buffer (restricting size of a log file for iOS app)

I'm currently redirecting NSLog() output to a file using a call to freopen() from the App Delegate. I would like to restrict the log file size, but doing this- unsigned long long fs = 3000; while ([fileAttributes fileSize] < fs) { …
Apophenia Overload
  • 2,485
  • 3
  • 28
  • 46
0
votes
1 answer

how to convert freopen of c++ in I/O stream of java

As i'm coding in java i have to read a file and write on java i have code in c++ freopen("addin.txt","r",stdin); freopen("addin.txt","w",stdout); i have to convert this code in java how could i ? i have tried this in java. int frw(){ File f1=new…
0
votes
1 answer

Why cant I read from this file after I have written to it and closed too?

I am trying to read from scene.txt, do calculations and write to stage1.txt then read from stage1.txt and write stage2.txt Finally, read stage2.txt and write stage3.txt; 1 and 2 work just fine. But, I am not quite sure, why can't I do the 3rd? I…
0
votes
0 answers

C freopen() causes Segmentation Fault

I have a part of C program: char buf[256]; fprintf(stderr, "buf created. going to freopen. Path:\n"); fprintf(stderr, path); fprintf(stderr, "\n"); if (!freopen(path, "a", stderr)) { fprintf(stderr, "if entered\n"); …
0
votes
0 answers

fprintf has last print statement printing to standard out

void print_tree(tree_node *thestruct,int* fd,int numKids) { FILE *fo = freopen("output2.txt","w",stdout); printf("%s",thestruct->line); fflush(stdout); int i = 0; char buff[20]; for(i=1; i < numKids+3; i++) { …
mitch lew
  • 1
  • 2
0
votes
0 answers

Input and output of a c code from file in android (without root)

For OJ problem solving I often face importance to have my outputs as a file. But freopen() does not work in android. Actually, there is a way that copy the code in a root diretory using Termux (or like apps) and then ./a.out
Tangent
  • 61
  • 1
  • 8
0
votes
2 answers

Any reason to reopen as "write-append" after "read-only"?

I have a save file containing a stream of program events. The program may read the file and execute the events to restore a previous state (say between program invocations). After that any new events are appended to this file. I could open the file…
Andreas
  • 5,086
  • 3
  • 16
  • 36
0
votes
0 answers

freopen stderr into file but getting it printed anyway into console

This is the schema of my code (for simplicity error control removed) main: freopen("error.txt","w",stderr);//redirecting stderr to error.txt FILE *fp=popen("./process", "w");//lunching a process pthread_t readerThread; /*reading output from…