0

Xcode ver: 14.1

My lecturer gave us a text file that contains more than 500 inputs for our C program. Hence I am trying to replicate "gcc test.c -o test && ./test < input.txt" in Xcode but I am not able to do it.

The closest I came accross was giving-command-line-arguments-in-xcode-in-c-program

I am running the same issue as how-to-use-test-input-file-in-xcode-c-by-using-command-line-arguments. But I was wonering if there was a workaround.

However, when I go into the edit scheme -> run -> argument and input "< input.txt". My custom input file just does not seem to work.

I have also tried to create a new copy file phase with my destination as my product directory.

scheme image

Any advice on how to go about it?

4
  • The whole "< someFile.txt" is not a command line argument to the program. That is a feature of the shell your command line app would normally be run in. This is also mentioned in the comments below the 2nd question you linked. Commented Mar 28, 2023 at 18:04
  • See stackoverflow.com/questions/48593939/… for a possible solution. Commented Mar 28, 2023 at 18:10
  • @HangarRash thank you I shall go and test it. I could not find this post when I was searching stackoverflow. Commented Mar 29, 2023 at 16:17
  • Alternatively, give your app an optional filename parameter, and use stdin if not provided. E.g., gist.github.com/robertmryan/653b1a6d465d4fac93cf8cf76ec43c84. That way, you can supply an argument of simply $PROJECT_DIR/input.txt (without the <), but it still supports the stdin pipe if your lecturer is really hung up on that. It might not pass muster with your lecturer, but is probably the right real-world solution. Commented Mar 29, 2023 at 23:27

0

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.