Like Tree2Likes
  • 2 Post By Salem

Copying Cuurent time to string

This is a discussion on Copying Cuurent time to string within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to copy the current time to a string but it throws a warning in dev c ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    12

    Copying Cuurent time to string

    Hi,

    I am trying to copy the current time to a string but it throws a warning in dev c of about some "numeric value conversion to the other string".....I don't remember exactly.....but is the code Ok??

    Code:
    #include<stdio.h>
    #include<time.h>
    #include<string.h>
    
    int main()
    {
    char dte[40];
    time_t present;
    time(&present);
    
    
    strcpy(date,ctime(&present));
    
    puts(date);
    
    getchar();
    
    return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    > .I don't remember exactly.....but is the code Ok??
    I'm guessing that since you don't remember the error message, that you also don't remember the code either.

    In other words, you just typed something and posted it here.
    Code:
    $ gcc -g -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:12:8: error: ‘date’ undeclared (first use in this function)
    foo.c:12:8: note: each undeclared identifier is reported only once for each function it appears in
    foo.c:7:6: warning: unused variable ‘dte’ [-Wunused-variable]
    It doesn't even compile.

    Come back when you can post the actual code you tried to compile, and the actual error messages you got.

    Otherwise, it's just a big waste of time.
    qny and AndiPersti like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-10-2011, 05:25 AM
  2. String copying
    By NegativeSpace in forum C++ Programming
    Replies: 7
    Last Post: 06-25-2008, 03:14 AM
  3. Copying a string, into a string array.
    By m.mixon in forum C Programming
    Replies: 5
    Last Post: 07-31-2006, 05:19 PM
  4. String copying
    By bobthebullet990 in forum C Programming
    Replies: 12
    Last Post: 11-28-2005, 08:31 AM
  5. Replies: 1
    Last Post: 10-31-2005, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21