Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:28:24+00:00 2026-05-16T08:28:24+00:00

I’ve recently been writing some basic command-line programs (I want to keep my skills

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:28:25+00:00Added an answer on May 16, 2026 at 8:28 am

    My thoughts:

    • Don’t call them NSxxxxx, NS is reserved for Cocoa and Foundation.
    • Both functions should be modified to accept a FILE* i.e. you should be modelling the interface to fprintf() and fscanf() for more flexibility.
    • Your printf function would probably be better if you used fputs()

    e.g.

    void NSFPrint (FILE* fp, NSString *format, ...) 
    {
        // Create the variable argument list.
        va_list args;
        va_start(args, format);
    
        // Using NSString, parse the argument list and convert it to a C string.
        fputs([[[[NSString alloc] initWithFormat:format arguments:args] autorelease] UTF8String], fp);
         va_end(args);
    }
    
    • Consider adding support for input and output in encodings other than UTF-8.
    • Your scanf replacement mixes C buffered IO and Unix unbuffered IO on stdin. This might be bad.
    • Your scanf replacement reads up to the end of the line even when it doesn’t need to. I haven’t checked carefully, but if the scan format does not consume the entire line, it looks like you are discarding input. This might be bad.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.