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?

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Shreamy
  • 341
  • 2
  • 16
  • 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. – HangarRash Mar 28 '23 at 18:04
  • See https://stackoverflow.com/questions/48593939/redirected-input-thorough-command-line-of-txt-file-into-xcodec for a possible solution. – HangarRash Mar 28 '23 at 18:10
  • @HangarRash thank you I shall go and test it. I could not find this post when I was searching stackoverflow. – Shreamy Mar 29 '23 at 16:17
  • Alternatively, give your app an optional filename parameter, and use stdin if not provided. E.g., https://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. – Rob Mar 29 '23 at 23:27

0 Answers0