Note that there are some explanatory texts on larger screens.

plurals
  1. POPrintf/scanf replacement methods: some feedback/advice needed
    primarykey
    data
    text
    <p>I've recently been writing some basic command-line programs (I want to keep my skills sharp over the summer), but <code>printf</code> and <code>scanf</code> have been starting to annoy me. I'm not a wonderful C programmer, and having to get into <code>printf</code>/<code>scanf</code> and their instabilities (or even worse, <code>fgets</code> and their ilk) isn't exactly putting me in a comforting setting (for this reason exactly, I love <code>NSLog</code>, with its comforting default namespace and its automatic <code>NSString</code> and <code>NSObject</code> parsing).</p> <p>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.</p> <p>And voila, I came up with my own <code>NSInput.h</code> file, containing two functions: <code>NSPrint()</code>, and <code>NSScan()</code>. These two functions are modeled much after printf and scanf, but also handle <code>NSString</code>'s. I know I'm treading on sacred namespace here, but I couldn't resist (<code>IFPrint</code> and <code>IFScan</code> just sound terrible!).</p> <p>Now, while I'm really happy that I have working code (for which you can find the source <a href="http://snipt.org/Xkoo" rel="nofollow noreferrer" title="NSInput.h">here</a>), I know that it's not efficient (much to my surprise, though, <code>NSPrint</code> is several times more efficient than <code>printf</code> 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. <code>NSScan</code>, for example, converts the <code>va_list</code> it recieves into an <code>NSPointerArray</code>, and uses <code>NSScanner</code>'s to scan through the format and input strings, so I know there's a lot of room for improvement.</p> <p><strong>Basically,</strong> 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 <code>printf</code> and <code>scanf</code>? Please tell me, I'm looking for input here (pun not intended!)...</p> <p><strong>Thanks in advance!</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload