3

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • This might get you started. http://stackoverflow.com/questions/9006801/difference-between-nslog-and-printf-statement-for-objectivec Hope it helps. – Frank Tudor Dec 06 '12 at 16:56
  • "It may sound strange that knowing a lot about iOS I am a newcomer to C." - It does, indeed. In general iOS development is done using Objective-C which is a superset of C - if you do iOS development, you should already be more than experienced in C. –  Dec 06 '12 at 16:56
  • @H2CO3 : I have been fully dedicated to Iphone programming. If my query links to this, I am bad programmer. Thanks for your opinion though :) – Nitish Dec 06 '12 at 17:02
  • I think the more interesting question would be to find average of n numbers using `printf` & `scanf`. I never knew these functions could do math. – user93353 Dec 06 '12 at 17:02
  • 1
    @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 :) –  Dec 06 '12 at 17:05
  • @user93353 : These will do no math. If used, they will input, output data. – Nitish Dec 06 '12 at 17:07
  • So basically your question is how to do input & output of numbers without using `printf` & `scanf`. – user93353 Dec 06 '12 at 17:09
  • @H2CO3 : I totally understand. It is really unfortunate part of me that I started with IOS, but someway fortunate :) – Nitish Dec 06 '12 at 17:09

1 Answers1

5

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).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111