I've recently been writing some basic command-line programs (I want to keep my skills sharp over the summer), but printf
and scanf
have been starting to annoy me. I'm not a wonderful C programmer, and having to get into printf
/scanf
and their instabilities (or even worse, fgets
and their ilk) isn't exactly putting me in a comforting setting (for this reason exactly, I love NSLog
, with its comforting default namespace and its automatic NSString
and NSObject
parsing).
Much to my disappointment, though, NSLog doesn't have a counterpart function, and prints a lot of extra 'junk' (time, function name, etc., along with a newline at the end), which defeats a lot of the purpose in my using it. So I decided to sit down for a different kind of programming exercise and write functions to replace printf and scanf that would meet my needs.
And voila, I came up with my own NSInput.h
file, containing two functions: NSPrint()
, and NSScan()
. These two functions are modeled much after printf and scanf, but also handle NSString
's. I know I'm treading on sacred namespace here, but I couldn't resist (IFPrint
and IFScan
just sound terrible!).
Now, while I'm really happy that I have working code (for which you can find the source here), I know that it's not efficient (much to my surprise, though, NSPrint
is several times more efficient than printf
under LLDB in Xcode 4, but that's beside the point). I need some advice on how to make the functions better, and more efficient. NSScan
, for example, converts the va_list
it recieves into an NSPointerArray
, and uses NSScanner
's to scan through the format and input strings, so I know there's a lot of room for improvement.
Basically, what I want to know is, are there any glaring mistakes I made that could and should be fixed? Is there anything huge that I missed? Should I just be called spoiled and go back to using printf
and scanf
? Please tell me, I'm looking for input here (pun not intended!)...
Thanks in advance!