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
2 answers

Opening Multiple files, alternatives to fopen()

I am a newbie programmer and am interested in competitive programming. I made a grader for COCI problems recently. In a function of this code, I take input from input files using a loop. Its file opening part looks like this - int next(int id) { …
Labib666
  • 3
  • 1
  • 3
0
votes
2 answers

C programming - freopen append a ? to the filename

I am writing a c program that simulates the linux shell. In order to implement i/o redirection using redirection symbol i.e. the > symbol, i make use of freopen to replace stdout with file specified by the user. If say the command is: environ >…
ImNoob
  • 145
  • 10
0
votes
3 answers

NSLog redirecting to a file will also write to /var/log/system.log

I have application where i have to maintain a log file for that app . I am logging by using NSLog . But this will also write to the system log .How to get rid of this . Approach : NSString *appending_filename=[log_dir_path…
user12345
  • 425
  • 1
  • 3
  • 14
0
votes
1 answer

freopen and execvp in c

I am doing a minor shell implementation in c, and I am stuck. I want to be able to redirect stdin and stdout, but I am confused. In, my shell, when I want to start a program, I use the execvp function. Now I would like to be able to redirect stdout,…
user1090614
  • 2,575
  • 6
  • 22
  • 27
0
votes
1 answer

Why doesn't my freopen function work?

#include #include #define MAXN 15 char forbid[MAXN][MAXN]; int dp[2][1<
Waceburg
  • 1
  • 2
0
votes
3 answers

Trying to create an output file with freopen, using non-constant string

I'm trying to create a file whose name is a string constant, but a string consisting of a constant string "List" an integer + + an extension. Here's my code: #include #include #include #include #include…
franvergara66
  • 10,524
  • 20
  • 59
  • 101
0
votes
1 answer

WriteFile to stdout fails after freopen

I have wrote the following code: int fd = _dup(fileno(stdout)); FILE* tmp = freopen("tmp","w+",stdout); HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); if (out == INVALID_HANDLE_VALUE){ //error } else if (out == NULL) { //error } else { …
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
0
votes
0 answers

File associated with the stdout stream

I have long multithreaded application,which code I can't add here. From main program I call freopen ("uniq_name",w+,stdout) After it different threads start to run .From some of them writing to stdout occures. From some of them writing to stderr…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
-1
votes
1 answer

C++ - my program stops running `freopen` function from

In my main.cpp: #include #include "hashtable.h" int main() { printf("1hello"); freopen("2.txt", "w", stdout); printf("2hello"); freopen("1.txt", "r", stdin); printf("3hello"); int type; char buffer[1000];int…
-1
votes
1 answer

C++: freopen (and I/O) just refuses to work

Today I'm having issues with my code. It appears that I can not get anything from input (whether file or stdin) as well as unable to print (whether from file or stdout). My code can have a lot of issues (well, this is code for a competitive…
-1
votes
2 answers

why is freopen() not working on Microsoft Visual Studio but working on CodeBlocks?

I started C++ not so long and searched so hard for different ways to read and write from/to files with no result until i tried it out on CodeBlocks which worked.. Images are attached below to point out possible errors in code though the same code…
lordvidex
  • 3,581
  • 3
  • 17
  • 25
-1
votes
1 answer

function freopen is not reading inputs

I'm trying to test freopen("inputs.txt","r",stdin); but it is not working.Here is my code below: #include using namespace std; int main() { freopen("inputs.txt","r",stdin); int n; cin >> n; cout << n << endl; …
-1
votes
2 answers

freopen and cout creating internal error

I'm trying to read and write some files, but i get "ERROR C1001, internal error happened in compiler" every time i try to std::cout something to my output.out file. Why ? (i used _CRT_SECURE_NO_WARNINGS in preprocesssor definition to be able to use…
NanBlanc
  • 127
  • 1
  • 12
-1
votes
1 answer

Writing cout to a file and then back to terminal

I'm currently writing a program that writes cout to a file, until the user presses control D. After that I would like to cout again to the terminal. Here is a sample of my code freopen(outputfile,"w",stdout); for(;;) { if(cin.fail()) //user…
Rob V
  • 17
  • 2
  • 4
-1
votes
2 answers

Freopen Multiple File input - C++

I have tried this ... for(int i=0;i>s!=NULL){doc[i]=doc[i]+s+" ";} fclose(stdin); ... } with name is a char "doc1.txt", "doc2.txt", ... but, this code only open…
malioboro
  • 3,097
  • 4
  • 35
  • 55
1 2 3 4 5 6
7