News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Input / output redirection before run

Started by POLGIA0, December 18, 2010, 09:44:58 AM

Previous topic - Next topic

POLGIA0

Hi, I'm not a professional programmer and I use CB to run Fortran code. Can someone suggest how to make input / output redirection in CB? More specifically I would like to read from a file instead than type input. From the console, this can be done with the console comand: program_name.exe< inputfilename. It should be possible to redirect input running the program by CB but I'm cannot find this possibility in the settings. Thanks in advance for your help.

xunxun

Project -- Set program's argument -- Select your target -- Program arguments
Regards,
xunxun

rajahks

I want to do something similar i.e redirect the contents of a file to the program so that rather than reading from stdin the program reads from the redirected input. Equivalent to pgm.exe < input

Is it possible to do this in code blocks ??

If  <input.txt is entered in the 'Program Arguments window:' it appears as a string in the char*argv[] parameter of main(..) function.

Thanks in advance.

vici

Quote from: xunxun on December 18, 2010, 01:43:47 PM
Project -- Set program's argument -- Select your target -- Program arguments

Your solution passes the string "<input.txt" to argv[0], so in the program, one needs to use fopen, fget... And that string as argument to fscaf() will fail, because of the redirection character at the beginning.

OP (and me as well) want to use only scanf to read the data, and not care about the file name.

Problem still unanswered, using Codeblocks 25.03 under Windows 10.