Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1040683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:15:16+00:00 2026-05-16T15:15:16+00:00

char * function decode time() { tm *ptm; //time structure static char timeString[STRLEN]; //hold

  • 0
char *  function decode time()
{ 

   tm *ptm; //time structure
    static char timeString[STRLEN]; //hold string from asctime()

    ptm = gmtime( (const time_t *)&ltime ); //fill in time structure with ltime

    if(ptm) 
    {

       strncpy(timeString, asctime( ptm ), sizeof(timeString) ); 
//EDIT  
sprintf(test, "Sting is: %s", timeString);


       return timeString;
.
.
} //end function

When I step through the code in the debugger I I can see the value of timeString is:
timeString CXX0017: Error: symbol “timeString” not found

However, when I remove the work “static” from timeString it does fill in correctly with the string but is now a local copy and will be destroyed.

Why am I not able to copy the string from this function into a static char array?

Visual Studio 6.0 – MFC

Thanks.

EDIT
the “test” string does contain the value of timeString.

I guess this is just a debugger issue? but why can’t I see the value of a static array in the debugger watch?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:15:17+00:00Added an answer on May 16, 2026 at 3:15 pm

    First, function name should be
    function_decode_time() not function decode time()

    with local static timeString will initialized entire with ‘\0’, without static its not guaranteed
    without static you the return value in calling context is undefined.

    strncpy will not added a ‘\0’ in timeString for use “sizeof(timeString)” , see definition;
    therefore YOU must added ‘\0’, eg:

    char * functionDecodeTime()
    {
      tm *ptm; /* time structure */
      static char timeString[STRLEN]; /* hold string from asctime() */
    
      memset( timeString, 0 , sizeof timeString ); /* entire content always is defined ! */
    
      ptm = gmtime( (const time_t *)&ltime ); //fill in time structure with ltime
    
      if( ptm )
      {
        strncpy(timeString, asctime( ptm ), sizeof(timeString)-1 );
      }
    
      return timeString;
    }
    

    If you use local static, your code is not reentrant/thread-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For reasons beyond my control, I need to return const char* from a function,
I have a function ClassA::FuncA(const char *filePath) and want to copy this const char
the prototype of the function ctime is char *ctime(const time_t *timep); As we can
I can't find bug in this code In function `BinaryCode::decode(std::string)': undefined reference to `BinaryCode::m_vecStr'
I am having trouble understanding this code: static long long _be_decode_int(const char **data, long
I'm trying to return a data structure from a function named urlTokener where in
In the following code I get a segmentation fault: Set *getpar() {...} char function(...)
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have a function: char *make_text(void) { char txt[MAXLEN]; //make something return txt; }
is there a performance difference between doing something like: void function() { char bufgfer[256];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.