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

asctime without trailing newline character

19
Hello, all. I am writing a patch of code that displays the time and date in the middle of the line. I am using the asctime function from ctime but I don't want the trailing newline character after the execution.

Is there any way to remove it, or should I go about finding the time using a different method?

Expand|Select|Wrap|Line Numbers
  1. ostream &td(ostream &stream)
  2. {
  3.   time_t t;
  4.  
  5.   t = time(NULL);
  6.   stream << asctime(localtime(&t));
  7.  
  8.   return stream;
  9. }
Dec 28 '07 #1
1 12572
weaknessforcats
9,208 Expert Mod 8TB
asctime returns a C-style string. The \n is the byte before the \0. Just change the \n byte to \0 and off you go.
Dec 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
4
by: fowlertrainer | last post by:
Hi ! I want to print, but without newline. I want to create a progress for ftp, but the print is drop a newline for every percent. I want like this: 0% 25% 50% 75% 100% But this happening:...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
4
by: Till Crueger | last post by:
Hi, I have a little problem with the following code: #include <stdio.h> int main(void) { char input='\0'; while(input!='q') { printf("Menu\n"); fflush(stdout);
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
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...
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
4
by: lihao0129 | last post by:
Hi, folks: I recently went through a strange problem with my Javascript code, say: I have a string variable which are from a 'textarea' element and I want to remove the trailing newlines inside...
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: 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?
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.