print sting using printf in main or functions?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 4
Reputation: satyanarayanam is an unknown quantity at this point 
Solved Threads: 0
satyanarayanam satyanarayanam is offline Offline
Newbie Poster

print sting using printf in main or functions?

 
0
  #1
May 9th, 2007
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..
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,867
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: print sting using printf in main or functions?

 
0
  #2
May 9th, 2007
check kerningham and ritchie, implement your own print functions using low level apis
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: print sting using printf in main or functions?

 
0
  #3
May 9th, 2007
Originally Posted by satyanarayanam View 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..
  1. puts(cString);
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: print sting using printf in main or functions?

 
0
  #4
May 9th, 2007
use putc() in a loop to display each character one at a time.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: print sting using printf in main or functions?

 
0
  #5
May 9th, 2007
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.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: print sting using printf in main or functions?

 
0
  #6
May 9th, 2007
>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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: print sting using printf in main or functions?

 
0
  #7
May 9th, 2007
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.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: print sting using printf in main or functions?

 
0
  #8
May 9th, 2007
>thus being very ineffective.
I don't see a "thus". These are two solutions and lacking some other restriction, both are equally effective.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: print sting using printf in main or functions?

 
0
  #9
May 9th, 2007
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.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: print sting using printf in main or functions?

 
0
  #10
May 9th, 2007
Originally Posted by dr4g View Post
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.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 2643 | Replies: 14
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC