0

I want for main function in c program, read argc and argv from file.

How to read argv and argc from file in C language?

For example:

./prog --test=cpu --prime=1000 run 

Change to:

./prog file.txt

File.txt is:

--test=cpu --prime=1000 run

Prog is a very big program.

1 Answer 1

3

You don't need to change the program, you can just do something like this:

./prog $(cat file.txt)

(assumung bash or similar shell).

Sign up to request clarification or add additional context in comments.

4 Comments

This also works for Windows PowerShell, by the way. If you are looking for something that works that way on cmd.exe, though, you are out of luck. ;-)
I need to change the program. Because cat in ./prog $(cat file.txt) causes the same inputs to be placed next to ./prog and I have trouble executing this binary in another program. Because the flags or arguments of the other program interfere with this binary.
@ZahraHeydari: sorry, that doesn't make any sense. Please edit your question to explain the underlying problem.
@ZahraHeydari: You did not say anything about another program before...?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.