944,111 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3157
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
May 9th, 2007
0

print sting using printf in main or functions?

Expand Post »
Hi,
This is satya,

how we can print a string in C that doesn't use printf in main or functions?
plz help on this

Thank u..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
satyanarayanam is offline Offline
4 posts
since May 2007
May 9th, 2007
0

Re: print sting using printf in main or functions?

check kerningham and ritchie, implement your own print functions using low level apis
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
May 9th, 2007
0

Re: print sting using printf in main or functions?

Hi,
This is satya,

how we can print a string in C that doesn't use printf in main or functions?
plz help on this

Thank u..
  1. puts(cString);
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
May 9th, 2007
0

Re: print sting using printf in main or functions?

use putc() in a loop to display each character one at a time.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
May 9th, 2007
0

Re: print sting using printf in main or functions?

Andor is correct.
the puts() function takes a String (char array) as the parameter.

putc() would output 1 character only, and not really useful or effective in this case.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
May 9th, 2007
0

Re: print sting using printf in main or functions?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 9th, 2007
0

Re: print sting using printf in main or functions?

Yes that's understood. What my point was. that. putc() outputs one character so if you wish to output words to the console, you'll need to LOOP for each character you wish to output. thus being very ineffective.
puts() would eradicate the need for looping altogether.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
May 9th, 2007
0

Re: print sting using printf in main or functions?

>thus being very ineffective.
I don't see a "thus". These are two solutions and lacking some other restriction, both are equally effective.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 9th, 2007
0

Re: print sting using printf in main or functions?

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.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
May 9th, 2007
0

Re: print sting using printf in main or functions?

Click to Expand / Collapse  Quote originally posted by dr4g ...
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Masking user input (password)
Next Thread in C Forum Timeline: help me





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC