My program implements a rudimentary scanner. It should be able to handle both file input and users manually entering input through the command line. My issue is being able to figure out which it is so I can handle it appropriately. Ideas so far:
I can assume there will be at least one whitespace character within a file or in a line of standard input. I'm thinking I could check
argv[1]
for whitespace, and if there's none, assume it's a file name and open the file.Alternately, I might try to use this to check if the file exists, open it if so, and handle it as command line entry otherwise.
Is there a simpler option that I'm missing? Are either of these two existing ideas more efficient and reliable than the other?