473,383 Members | 1,737 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,383 software developers and data experts.

testing for the newline

I have a variable that seems to be placing a newline when outputting to
a file. How can I test to see if this is the case.

Nov 14 '05 #1
4 2395
bacadman <ba******@gmail.com> wrote:
I have a variable that seems to be placing a newline when outputting to
a file. How can I test to see if this is the case.


Show us the code you're using, perhaps then someone can tell you what's
going wrong. A variable as such never outputs anything. It's probably
your call of printf() (or whatever you're using to print the variables
value).
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
On 24 Jan 2005 10:28:06 -0800, "bacadman" <ba******@gmail.com> wrote:
I have a variable that seems to be placing a newline when outputting to
a file. How can I test to see if this is the case.


if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
Nov 14 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

chaka wrote:
On 24 Jan 2005 10:28:06 -0800, "bacadman" <ba******@gmail.com> wrote:

I have a variable that seems to be placing a newline when outputting to
a file. How can I test to see if this is the case.

if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';


Which is a good way to kill off the trailing newline in a string.

But, the OP didn't make it clear that this is what is happening. It could be
that the newline is a single character (as in printf("%c",'\n'); ), or even
imbedded at some point inside a string (as in printf("%s","abc\n123"); ).

Neither of these cases are addressed by your (good) code fragment.

- --
Lew Pitcher
IT Consultant, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFB9VcyagVFX4UWr64RAg/qAKDwWTBYHWYam+/EVFHRH4E7mTB3BACgyPoC
NZMIpob3XRWgMM1Rgl15kTw=
=iICq
-----END PGP SIGNATURE-----
Nov 14 '05 #4

"chaka" <ch***@zulu.com> wrote in message
news:8a********************************@4ax.com...
On 24 Jan 2005 10:28:06 -0800, "bacadman" <ba******@gmail.com> wrote:
I have a variable that seems to be placing a newline when outputting to
a file. How can I test to see if this is the case.


if(line && *line) if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';


We don't want to look at memory outside
the string!

-Mike
Nov 14 '05 #5

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

Similar topics

9
by: Alan Mackenzie | last post by:
To all those who use (X)Emacs's CC Mode to edit C, C++, Java, Objective-C, Pike, AWK or IDL: To help direct the development of CC Mode, it would be useful to find out how people use the...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
7
by: Alex Nordhus | last post by:
I am looking for a way to strip the blank line and the empty newline at the end of the text file. I can get the blank lines removed from the file but it always leaves the end line (which is blank)...
4
by: Peter Kirk | last post by:
Hi I would like to ask a little bit about the value Environment.Newline: what is it and what is the point of it? Ok, I can see in the docs that it represents "newline" for the current platform -...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
5
by: Adam Right | last post by:
Hi, Is there a way to construct the mail body including newline characters by using .net framework mailing functions when sending an email? I cannot insert newline character into the body of the...
11
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const...
12
by: zzapper | last post by:
Hi, Have tried to google this without 100% satisfaction. A function reads a mysql record into an array and returns it, if it doesnt exist it returns '' or FALSE. What ways do I have to test...
1
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.