check kerningham and ritchie, implement your own print functions using low level apis
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
use putc() in a loop to display each character one at a time.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
>putc() would output 1 character only, and not really useful or effective in this case.
You must have missed the part where he said "in a loop" and "to display each character one at a time". Of course, the question is a bit ambiguous.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>thus being very ineffective.
I don't see a "thus". These are two solutions and lacking some other restriction, both are equally effective.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Well are you going to design a for loop to loop through and output chars each time? or just call one function to do it. I think we all know which is the most appropriate.
Re-read the original question -- does not say anything about which method is the most effective or requires the least coding. Actually fwrite() will work as well. I think teachers in college ask silly questions like this one just to see if the student has any imaginagion.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Optimization is implied, especially for procedural programming. No-one will write 10 lines of code of they can write one.
And i agree, my lecturers gave silly exercises out, and you werent allowed to use the standard methods that you'd normally do.
Pain in the butt if you ask me.
I agree that nobody would write a program in the real world like that, or they shouldn't anyway. But college is not even close to being the real world. So who knows what the instructor wants:)
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
>I think we all know which is the most appropriate.
Nope, it seems to just be me. Given the extremely vague requirements, it's hard to say what's most appropriate, but it's easy to imagine an extended requirement of processing each character before printing. Discarding whitespace, for example. If I had my way, we would have pressed for more information from the OP rather than made assumptions left and right.
>No-one will write 10 lines of code of they can write one.
Which explains why bubble sort is so popular. :icon_rolleyes:
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>there are 2 ways...
Only two?
>main()
int main ( void ), and you need to return an integer.
Both of those solutions are unnecessarily complicated. Can you tell me what's wrong with this?
#include <stdio.h>
int main ( void )
{
puts ( "Hello satya!" );
return 0;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401