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 8779573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:49:25+00:00 2026-06-13T19:49:25+00:00

i have some code: char * itoa(int a) { char (*t)[16]=(char(*)[16])malloc(1*sizeof(char[16])); sprintf(*t,%d,a); return *t;

  • 0

i have some code:

char * itoa(int a)
{
    char (*t)[16]=(char(*)[16])malloc(1*sizeof(char[16]));
    sprintf(*t,"%d",a);
    return *t;
}
// ...
mvwprintw(my_menu_win,i+1,2,itoa(i));

can i free memory from malloc, without add temporary variables?
e.g:

temp=itoa(i);
mvwprintw(my_menu_win,i+1,2,temp);
free(temp);
  • 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-06-13T19:49:26+00:00Added an answer on June 13, 2026 at 7:49 pm

    In short: No.

    To free allocated memory you need a reference to it.

    If you could change your conversion API, a possible work around could be to use an externally provided buffer:

    char * itoa(char * t, int i)
    {
      sprintf(t,"%d",a);
      return t;
    }
    

    Call itoa() this way then:

    {
      char buffer [16];
    
      mvwprintw(my_menu_win,i+1,2,itoa(buffer, i));
    }
    

    Alternatively (C99 only) one could do the call to itoa() this way:

    mvwprintw(my_menu_win,i+1,2,itoa((char[16]){0}, i));
    

    So to clean up this a macro helps:

    #define ITOA_0(i) itoa((char[16]){0}, i) /* init array with 0s */
    #define ITOA(i) itoa((char[16]){}, i) /* do not init array with 0s -> faster, but none ISO */
    
    ...
    
    mvwprintw(my_menu_win,i+1,2,ITOA(i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently made changes in some code that makes a char name field
I have some code that is supposed to return an NSString. Instead it is
I have some code defined as follows: typedef long (*ShellExecFunct)(long, const char*, const char*,
I have some code: a declaration of a queue: typedef deque<char*, allocator<char*> > CHARDEQUE;
I have some code: a declaration of a queue: typedef deque<char*, allocator<char*> > CHARDEQUE;
I have some C++ code written in C-style. For some reasons I can't use
I have some code in my application that looks something like this: char *hash
I have some code that stack dumps when using sprintf to copy a a
I have some code but it wan't compile. I can't go further with this
I have some c(++) code that uses sprintf to convert a uint_64 to a

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.