returning strings

This is a discussion on returning strings within the Windows Programming forums, part of the Platform Specific Boards category; char *GetFormattedTime() { char Time[1024]; ZeroMemory(Time, sizeof(Time)); GetTimeFormat(LOCALE_USER_DEFAULT, NULL, NULL, "hh':'mm':'ss tt", Time, sizeof(Time)); return Time; } now, this works ...

  1. #1
    Unregistered
    Guest

    returning strings

    char *GetFormattedTime() {
    char Time[1024];
    ZeroMemory(Time, sizeof(Time));
    GetTimeFormat(LOCALE_USER_DEFAULT, NULL, NULL, "hh':'mm':'ss tt", Time, sizeof(Time));
    return Time;
    }

    now, this works when i go "
    MessageBox(NULL, GetFormattedTime(), "", MB_OK);

    but when i try to write to a file:
    fprintf(FILE, GetFormattedTime());

    it only prints two characters: 0
    any ideas what's wrong?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    I believe you're missing your formatting:

    /code

    fprintf( stream, "%s", GetFormattedTime( ) );

    /code

    See if that doen't help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does returning newly-declared strings cause leaks?
    By Anvilsmith in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2008, 12:01 PM
  2. Returning strings?
    By DBProgrammer in forum C++ Programming
    Replies: 4
    Last Post: 09-26-2007, 08:15 PM
  3. Returning Strings
    By Overload in forum C++ Programming
    Replies: 14
    Last Post: 07-29-2004, 08:05 PM
  4. Please help with String class, returning strings
    By skanxalot in forum C++ Programming
    Replies: 4
    Last Post: 09-24-2003, 11:48 AM
  5. correct way of returning strings
    By marsface in forum C++ Programming
    Replies: 5
    Last Post: 06-11-2003, 11:33 AM

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