Input/ Output alternatives for printf/scanf

10,022

No, neither printf nor scanf is really needed for this.

The obvious alternatives would be to read the input with something like getc or fgets and convert from characters to numbers with something like strtol.

On the output side, you'd more or less reverse that, converting from numbers to characters (e.g., with itoa which is quite common, though not actually standard), then printing out the resulting string (e.g., with fputs).

Share:
10,022

Related videos on Youtube

Nitish
Author by

Nitish

With practice comes clarity

Updated on August 29, 2022

Comments

  • Nitish
    Nitish over 1 year

    It may sound strange that knowing a lot about iOS and having some experience in .net, I am a newcomer to C. Somewhere I got this target to find average of n numbers without using printf and scanf. I don't want the code for the program but I am seeking alternatives to the mentioned functions.

    Is code with printf/scanf required here? Also do let me know if my query stands invalid.

    • Admin
      Admin over 11 years
      @Nitish Actually, I'm not saying you would be a bad programmer - I'm just saying that you should really know C (and the standard library) forwards and backwards beforehand :)
  • Nitish
    Nitish over 11 years
    Thanks Jerry, will try this and let you know.
  • user93353
    user93353 over 11 years
    If sprintf is allowed, you can use it instead of itoa cos it's standard. And of course, if C++ is allowed, then use ostringstream.