473,793 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2081
ju**********@ya hoo.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**********@ya hoo.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...@y ahoo.co.in"
<junky_fel...@y ahoo.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**********@y ahoo.co.inwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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**********@y ahoo.co.in" <ju**********@y ahoo.co.inwrite s:
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*jab ber.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**********@ya hoo.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
5565
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 integer arrays and the individual 1's and 0's are being written out as integers.
1
3906
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 CR-LF pairs such as "this is a long entry\r\nThis is the secondline". I'm building an XML document to represent my Excel data. This is
5
1618
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)) but it only get rid of the ' and not
3
3287
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 to the user as calculations become visible. I'm writing a web interface which takes the input values from user, updates the excel sheet and returns the recalculated output from the excel file. I'm using ADO.Net to update and read the excel file.
16
1817
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 puts each string on a separate line. So the code is: import csv output = csv.writer(open('/Python25/working/output.csv', 'a')) a = for elem in range(len(a)):
3
4766
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 the loop exits. However i feel this will be a bit slow, is there any way the entire buffer's contents in RAM can be copied directly into the file?
1
2974
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 : Defines the entry point for the console application. #include "stdafx.h" #include <stdio.h> #include <conio.h> #include <iostream>
4
1802
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 XP in IDLE. I have some simple code I wrote to open a large log file with 39 extra characters starting each line that I want to strip out. Then I just want to rewrite the lines in a new file without those 39 preceding characters per line. ...
2
2260
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 <stdlib.h> //needed for converting integers to strings #include <iostream> //needed for in/out commands ie. cin/cout #include <fstream> //needed to open readable/writeable files ie. ifstream/ofstream #include <string> //needed to create strings from...
2
2171
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 streamwriter, it looses the final packet. Strangely, If I output the datapackets to a console from the telnet server, it perfectly gets all the output packets. the code snippet is below: StreamWriter sw = new StreamWriter("c:\\output.txt",...
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.