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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:25:36+00:00 2026-05-17T17:25:36+00:00

I am having a pointer *ip_address_server which holds the ip address of the server

  • 0

I am having a pointer *ip_address_server which holds the ip address of the server :

   in_addr * address = (in_addr * )record->h_addr;
    char *ip_address_server = inet_ntoa(* address);

Clearly, when I use printf to print the value of it, it gets nicely printed.

printf("p address %s" , ip_address_server);

But now if I declare an array of say size 20 to hold the value then I need to copy the content from the pointer to the array.

char host_name[20];

To copy the value I used a for loop. But the value that I print later is not the right value.

for(int i = 0; ip_address_server[i] != '\0'; i++) 
        host_name[i] = ip_address_server[i];
    printf("hostname %s \n" , host_name);

I think there is some error with the terminating condition.

Am I wrong in my approach or is there any alternative way out for this?

  • 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-17T17:25:37+00:00Added an answer on May 17, 2026 at 5:25 pm

    Safe & better way to do it:

    snprintf(host_name, sizeof(host_name), "%s", ip_address_server);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I use the method doSomething like this; first having assigned the pointer to
Having an untyped pointer pointing to some buffer which can hold either ANSI or
I'm having troubles understanding pointer arithmetic or how memory is assigned. In the code
I am having a new little problem; I have a little pointer called: int
I need to implement an auxilliary function, named copyList, having one parameter, a pointer
I am rewriting some code from having a regular pointer to where the pointer
I'm having a problem with the this pointer inside of a custom class. My
I'm having trouble passing a pointer to a structure as an argument to a
I am having problem with the contents of a pointer passed as the wParam
I am having a problem placing an instance of my reference-counting Pointer <Type> class

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.