How can i pass the content of file as an arguments to some function?

59 Views Asked by At

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 ?

1

There are 1 best solutions below

0
onequbit On

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