Processing delimiter characters in C?
It would be helpful for you to break up the code into functions, that will simplify each task.
Process the command line arguments first, then once you have the delimiter process the text files.

Declare the variable delim above any logic and initialize it to the default value
Process the command line to get the actual delimiter.
Process the input file.

This should shorten the code because you only need one loop to process the input file rather than 2.