Replit making errors when it shouldn't

Problem description:
It’s making errors that shouldn’t be happening. I tried my code on other compilers, and it worked. Also, before, on some older version of replit the EXACT SAME code worked.
In case your curious, the error is with the freopen() in c++.

Expected behavior:
It shouldn’t produce an error; run normally.

Actual behavior:
Produces an error

Steps to reproduce:
I don’t know if it happens with other functions, but just test the freopen thing like

freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);

in c++.
Bug appears at this link:
https://replit.com/@Ivanzong/File-inputoutput#main.cpp

Browser: Chrome
OS: Windows
Device (Android, iOS, NA leave blank): NA
Desktop app version (Avatar menu->“Version”) or NA: NA
Plan (Free, Replit Core): Core but I think it doesn’t matter

This has to do with return values. The function declaration looks something like:

FILE* freopen(blah blah blah)

With the makefile setup replit has (I assume you haven’t fiddled with yours), it throws lots of errors most compilers are allowed to ignore. It’s better this way, at least for most people.

Anyways, freopen returns a value of type FILE*, so to fix the error, you can either create a variable of type FILE* or learn to modify the makefile to ignore “-Wunused-result”.

P.S. Next time, try and describe the actual error in the question so I don’t have to open your repl right away.

P.P.S. Check out https://cplusplus.com/reference/cstdio/freopen/ if you still have questions.

1 Like