Skip to content
TFE Times

TFE Times

Business, Technology, and Culture

Click here
Click here
MAFI_728x90
Click here
MAFI_728x90
NYU Tandon School of Engineering Leaderboard
University of California Irvine Leaderboard
University of California Irvine Leaderboard
Brandeis University Master of Finance Leaderboard 728x90
RPI Leaderboard
  • Business
  • Culture
  • Technology
  • International Rankings
    • Bangladesh
    • Canada
    • Egypt
    • India
    • Nigeria
    • Pakistan
    • Philippines
    • United Kingdom
    • United States of America
  • Masters Rankings
    • Accounting
    • Business Analytics
    • Chiropractic
    • Computer Engineering
    • Computer Science
    • Economics
    • Education
    • Finance
    • Financial Economics
    • Financial Engineering
    • Law
    • Management
    • Marketing
    • MBA
    • Nursing
    • Social Work
  • Resources
    • C++
      • Beginner’s Guide to C++
      • An Introduction to the Imperative Part of C++
      • C++ Code
        • Sorts
        • Binary Search Trees
        • Strings
        • Binary Search
        • Math
        • Quant
        • Puzzles/Games
        • Language Concepts
        • Graphics
        • OS Operations
        • Graphs
      • C++ Full Course
      • C++ Crash Course
      • C++ Interview Questions
      • C++ Q/A
      • C++ Books
      • C++ Free Books
      • C++ Videos
    • C Questions
    • C Programming Tips
    • Java Questions
    • Quant Data Sources
    • Quant Questions

C++: Hostname

Posted on September 1, 2017April 1, 2018 by TFE Times
Posted in C++Tagged c, host, hostname, name, routine
Bjarne-stroustrup
 

Find the name of the host on which the routine is running.

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>

int main(void)
{
	char name[_POSIX_HOST_NAME_MAX + 1];
	return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

SOURCE

Content is available under GNU Free Documentation License 1.2.

Related

Post navigation

Bjarne-stroustrup
← Previous

C++: JSON

September 1, 2017
C
Next →

Obfuscated C Code Contest 2006. Please explain sykes2.c

September 1, 2017

Related Posts

Bjarne-stroustrup

C++: Apply a Callback to an Array

Posted on September 1, 2017April 1, 2018
C_plus_plus_at_woodlands_school

C++: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?

Posted on September 1, 2017April 1, 2018
Bjarne-stroustrup

C++: Linear Congruential Generator

Posted on September 1, 2017April 1, 2018
University of California Berkeley Master of Financial Engineering MFE Sideboard
NYU Tandon School of Engineering Sideboard
output_8BgzjE
Brandeis Business School
University of California Irvine Leaderboard
Click here
  • Democracy Around The World

    November 11, 2025June 27, 2025 by TFE Times
  • Income Tax Rate By State

    November 10, 2025June 27, 2025 by TFE Times
  • How a Truck Accident Attorney Can Help You Maximize Your Compensation

    November 9, 2025 by TFE Times
  • The Impact of Compliance with Regulation on Multi-State Transportation Insurance

    November 9, 2025 by TFE Times
  • Top 50 Science/Tech Clusters

    November 9, 2025June 27, 2025 by TFE Times
  • Business Survival Rates In The U.S.

    November 8, 2025June 27, 2025 by TFE Times
  • Price Parity By State

    November 7, 2025June 27, 2025 by TFE Times
  • Nvidia’s Market Cap Compared To Banks

    November 6, 2025October 29, 2025 by TFE Times
  • Future Electricity Usage By Country

    November 5, 2025June 27, 2025 by TFE Times
  • How Terrestrial Carbon Storage Works

    November 4, 2025June 27, 2025 by TFE Times

Copyright © TFE Times, LLC. All Rights Reserved.

Terms of Service | Privacy Policy | Disclaimer

WordPress Theme : Eight Paper by 8Degree Themes