User Profile

Collapse

Profile Sidebar

Collapse
karlc
karlc
Last Activity: May 16 '07, 10:20 AM
Joined: Mar 19 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • karlc
    replied to sprintf() problem
    in C
    Horace1

    Yes. It was what I did as you said.

    Is it OK not to call free() in the fun()?

    Charles...
    See more | Go to post

    Leave a comment:


  • karlc
    replied to sprintf() problem
    in C
    Dear Horace1

    Glad to receive your reply again. You example worked well. Thank for your time.

    However, I would like to keep return type of fun() be char*, because the function will be called by macro like:

    #define MACRO1 fun("aaa")
    #define MACRO2 fun("bbb")
    ....

    I though malloc() could help as you advised. The only problem was how to free the memory in the...
    See more | Go to post

    Leave a comment:


  • karlc
    replied to sprintf() problem
    in C
    Dear Horace1

    malloc() did solve the problem. It is what I expected. Thank you.

    However, as you reommended, how could I free() the memory if I need to return sTmp in the fun()? Could I free() the memory outside the fun()?

    Please help.

    Thank you

    Charles
    See more | Go to post

    Leave a comment:


  • karlc
    replied to sprintf() problem
    in C
    Sorry for my mistake. There shouldn't be static keyword.

    If fact, the problem still existed when I removed it.

    Please help. Thank you.
    See more | Go to post

    Leave a comment:


  • karlc
    replied to sprintf() problem
    in C
    Dear horace1

    So how could I fix this problem? Please help.

    Charles...
    See more | Go to post

    Leave a comment:


  • karlc
    started a topic sprintf() problem
    in C

    sprintf() problem

    I encountered the problem as follows:
    Code:
    #include <stdio.h>
    
    char* fun(char* b)
    {
      char* sTmp;
      static char d[BUFSIZ];
      bzero(d, BUFSIZ);
      sprintf(d, "%s:%s", "Test", b);
      sTmp = d;
      return  sTmp;
    }
    
    main()
    {
      char a[100];
      char b[100];
      char tmp[100];
      bzero(tmp, 100);
      strcpy(a,
    ...
    See more | Go to post
    Last edited by horace1; Mar 19 '07, 09:26 AM. Reason: added code tags
No activity results to display
Show More
Working...