473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

writing a string to output

Hi guys,

I want to write a null terminated string to the standard output. I
don't want to use
printf as it may be costly. I am using "puts" library function, but it
appends the
newline to the end of string which I do not want. Is there any library
function which
does not append the newline character ?

Also, any idea why does puts appends newline to the input string ?

There's another library function "fputs" that does not append the
newline character.
I was wondering why puts appends newline but fputs does not ? Is there
any special
reason for this ?

thanks a lot for any help in advance ...

Oct 6 '06 #1
7 2067
ju**********@yahoo.co.in wrote:
Hi guys,

I want to write a null terminated string to the standard output. I
don't want to use
printf as it may be costly.
Have you measured it and found it too costly for you application?

I am using "puts" library function, but it
appends the
newline to the end of string which I do not want. Is there any library
function which
does not append the newline character ?

Also, any idea why does puts appends newline to the input string ?
I'm afraid the answer is "because that's what the standard says they do"
--
Ian Collins.
Oct 6 '06 #2
Ian Collins wrote:
ju**********@yahoo.co.in wrote:
>Hi guys,

I want to write a null terminated string to the standard output. I
don't want to use
printf as it may be costly.

Have you measured it and found it too costly for you application?

I am using "puts" library function, but it
> appends the
newline to the end of string which I do not want. Is there any library
function which
does not append the newline character ?

Also, any idea why does puts appends newline to the input string ?
I'm afraid the answer is "because that's what the standard says they do"
The standard also provides fputs, which the OP might find useful.
Oct 6 '06 #3


On Oct 6, 4:55 pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:
Hi guys,

I want to write a null terminated string to the standard output. I
don't want to use
printf as it may be costly. I am using "puts" library function, but it
appends the
newline to the end of string which I do not want. Is there any library
function which
does not append the newline character ?

Also, any idea why does puts appends newline to the input string ?

There's another library function "fputs" that does not append the
newline character.
I was wondering why puts appends newline but fputs does not ? Is there
any special
reason for this ?

thanks a lot for any help in advance ...
`puts' is the most convenient function for printing simple messages.
For example:

puts ("This is a message.");

outputs the text `This is a message.' followed by a newline.

So I think the reason is conveniency.

Oct 6 '06 #4

<ju**********@yahoo.co.inwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi guys,

I want to write a null terminated string to the standard output. I
don't want to use
printf as it may be costly. I am using "puts" library function, but it
appends the
newline to the end of string which I do not want.

There's another library function "fputs" that does not append the
newline character.
You answered your own question: 'fputs' to FILE 'stdout'.

If you still need the formatting ability, you can use 'sprintf' and 'fputs'.
Many implementations have a single core routine for the various *printf
functions. You'll need to check to see how much is actually saved with
'fputs' with 'sprintf' versus 'printf'.

However, you may be able to reduce things further. Many 'fputs' routines
add buffering and output the string using a 'putc' while loop. If you don't
need the buffering, write your own.
Rod Pemberton
Oct 6 '06 #5
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrites:
I want to write a null terminated string to the standard output. I
don't want to use printf as it may be costly.
Honestly I doubt it that it is costly even though I prefer using
puts()/fputs() to printf()/fprintf() when it's possible.
I am using "puts" library function, but it appends the newline to
the end of string which I do not want. Is there any library function
which does not append the newline character ?
fputs, like: fputs(string, stdout);
Also, any idea why does puts appends newline to the input string ?
Because the standard says so.
There's another library function "fputs" that does not append the
newline character.
So after all you already knew the answer to the former question.
I was wondering why puts appends newline but fputs does not ? Is
there any special reason for this ?
Yes - C standard.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Oct 6 '06 #6
You may have a misplaced interest in efficiency. The physical I/O to
standard output, whether it be a TTY, a virtual TTY, or redirected to a
file, is likely to be the bottleneck, not the small overhead in calling
printf(). If you step thru the code, from entering printf(), to it
seeing the "%s" format spec, to moving the string to the output buffer,
is well under 100 instructions.
That's much less time than what it takes to write to a console or a
disk.

Oct 6 '06 #7
ju**********@yahoo.co.in wrote:
"puts" library function
Is there any library function which
does not append the newline character ?
There's another library function "fputs" that does not append the
newline character.
That's what I was thinking.

I think of puts as converting strings into lines.
Strings in memory are somewhat analagous to lines of text in a file.
Strings are '\0' terminated and lines are '\n' terminated.

--
pete
Oct 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
1
by: Tomas Vera | last post by:
Hello All, I'm having trouble writing some special characters to an XML file. I need to output a XMLSS formatted file to be read by Excel. In some cells there will be some text that contains...
5
by: eight02645999 | last post by:
hi i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on ..... I tried this re.sub(r" '() ",'',str(output))...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
16
by: lisa.engblom | last post by:
I have two semi related questions... First, I am trying to output a list of strings to a csv file using the csv module. The output file separates each letter of the string with a comma and then...
3
by: sam_cit | last post by:
Hi Everyone, I have a buffer having some raw ASCII data and i want to write it into a file. One way is to loop through the buffer and write a single character at a time and close the file after...
1
by: Smita Prathyusha | last post by:
I am facing a problem in writing to COM1. I am using a Win 32 Console mode Program in VC++ the following is the code: If anyone can help me out it will be of great help : // SC_Using_Classes.cpp...
4
by: FingerDemon | last post by:
I'm guessing I'm missing something obvious here, but I have searched around and re-read my Python books and references on simple file writing and I can't see the answer. I am running this in Windows...
2
by: mauricesmith42 | last post by:
Sorry i know this is rather large to be posting, but in order to understand the question you have to see all the code //#include <windows.h> //needed for opening folders #include...
2
by: =?Utf-8?B?S3VtYXI=?= | last post by:
I am using granados telnet client for connecting to the telnet and get the data from it. Every thing appears to be going smooth. But for some reason when I try to write the byte data to a string or...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.