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

  • Home
  • SEARCH
  • 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 8442221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:47:34+00:00 2026-06-10T08:47:34+00:00

Main: char *tmpip; tmpip = get_public_ip(); function get_public_ip: char * get_public_ip(void){ char *ipresult; if(((ipresult

  • 0

Main:

char *tmpip;
tmpip = get_public_ip();

function get_public_ip:

char * get_public_ip(void){
    char *ipresult;

    if(((ipresult = malloc(17))) == NULL){
        perror("malloc on pub ip");
        exit(1);
    }


    if(fgets(ipresult, 16, tmpfp) == NULL){
        perror("fgets error pubip");
        exit(1);
    }
    fclose(tmpfp);
    return ipresult;
}

My question is:
it is good to do inside the main free(tmpip) or it is wrong?

  • 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-10T08:47:35+00:00Added an answer on June 10, 2026 at 8:47 am

    It’s a good way of coding: you malloc() some memory in a function and free() it when not needed anymore. Be sure to comment your function or prototype that it will malloc() the memory needed, so you know that you have to free() it.

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

Sidebar

Related Questions

I have main function like this: void main() { char *s; inputString(s); printf(%s,s); }
int main() { char *p; p = (char* ) malloc(sizeof(char) * 0); printf(Hello Enter
int main() { char *s1, *sTemp; s1 = (char*)malloc(sizeof(char)*7); *(s1 + 0) = 'a';
I have the following code: main.c #include checksum.h void main() { char *Buf =GPGGA204502.005106.9813N11402.2921W1090.91065.02M-16.27M;
#inlcude <stdio.h> #inlcude <stdlib.h> #inlcude <string.h> int main() { char *buff = (char*)malloc(sizeof(char) *
int main () { char *destination; char source[10] = jigarpatel; destination = (char*) malloc(5);
int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, test, 5); }
void main() { char str[2][7] = {1234567, abcdefg}; char** p = str; printf(%d\n, *(p+1));
I came across the following code: int main() { char *A=(char *)malloc(20); char *B=(char
void main() { char s[]=\12345s\n; printf(%d,sizeof(s)); } When i compile it it giving 6.

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.