LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2006, 08:13 PM   #1
thanhvn
Member
 
Registered: Mar 2005
Location: CA
Distribution: RHEL3, FC4
Posts: 46

Rep: Reputation: 15
how to suppress the newline in the formatted string returned by ctime?


In C++, the ctime function (from <ctime> or <time.h>) returns a formatted date and time string. However, this string contains a newline. What is the simplest way, in C++ syntax, to remove the newline?
Thanks,
 
Old 06-20-2006, 08:36 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Code:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <time.h>

int main() {
    char buf[256];
    time_t tt;

    time(&tt);
    strcpy(buf,ctime(&tt));
    buf[strlen(buf)-1]='\0';
    printf("%s\n",buf);
    return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ctime of /etc/samba/smbpasswd different ddaas Linux - Security 0 07-04-2005 01:42 AM
Can U suppress X Windows on Load? goodboy Linux - Software 7 04-20-2005 10:04 PM
mtime/ctime changed on directory entries stardot Linux - Security 2 11-29-2004 10:44 PM
Weired ctime() asctime() output azi Programming 1 07-01-2004 04:48 PM
how to suppress colors frankie_g Linux - Newbie 6 05-15-2002 10:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration