-2

given file a.txt how can I pass the content of this file as arguments to the main function ?

for example:
a.txt:

a b c d e

and the main function is:

int main(int argc, char *argv[]);

And I want to pass the content of this a.txt file as arguments to main function. Namely, the arguments will be: a b c d e.

How can I do it via Eclipse compiler ?

  • Why do you want to do it? – Phalgun Sep 15 '22 at 19:39
  • @Phalgun Because that I want to parser some file that I have in this way and to understand what is the chars that appears there – StudentOrint Sep 15 '22 at 19:46
  • Why not read it from file within your program? But to your question - there is a `xargs` utility in Linux. Maybe there is something for windows too. – Eugene Sh. Sep 15 '22 at 19:49
  • @meaning-matters how strange, in the link you provide the accepted answer with 294 upvotes does not work (it sends the whole file as a single argument) – David Ranieri Sep 15 '22 at 20:19

1 Answers1

0

In Eclipse, you can configure parameters for running your code in the IDE... https://www.tutorialspoint.com/eclipse/eclipse_run_configuration.htm

But programatically you will need a script that reads the contents of the file and constructs the command-line that invokes main() with those file contents as command-line parameters.

Or for an elegant one-liner, see this answer by David Ranieri... https://stackoverflow.com/a/73736630/20006834

onequbit
  • 1
  • 1