Skip to content
TFE Times

TFE Times

Business, Technology, and Culture

University of California Irvine Leaderboard
University of California Irvine Leaderboard
NYU Tandon School of Engineering Leaderboard
Brandeis University Master of Finance Leaderboard 728x90
Click here
University of Maryland Masters of Economics  Leaderboard
MAFI_728x90
RPI Leaderboard
Click here
Click here
MAFI_728x90
University of Maryland Masters of Economics 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++: Happy Numbers

September 1, 2017
C
Next →

Obfuscated C Code Contest 2006. Please explain sykes2.c

September 1, 2017

Related Posts

Bjarne-stroustrup

C++: Do While Loop

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

C++: Evaluate Binomial Coefficients

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

C++: Happy Numbers

Posted on September 1, 2017April 1, 2018
output_8BgzjE
University of Maryland Masters of Economics Sideboard
NYU Tandon School of Engineering Sideboard
University of California Irvine Leaderboard
University of Maryland Masters of Economics Sideboard
Brandeis Business School
Click here
University of California Berkeley Master of Financial Engineering MFE Sideboard
  • Why Businesses Are Moving Toward Instant Payments

    May 13, 2026 by TFE Times
  • Foreign Direct Investment In Emerging Markets Over Time

    May 13, 2026November 9, 2025 by TFE Times
  • 5 Add-Ons You Should Buy Only if You Ride in Certain Conditions

    May 12, 2026 by TFE Times
  • GameZone Arcade Games: Mobile-Friendly Entertainment Anytime, Anywhere

    May 12, 2026May 12, 2026 by TFE Times
  • Best Financial Engineering Program Rankings

    What Does Financial Literacy Actually Teach Students Today?

    May 12, 2026 by TFE Times
  • Most And Least Safest Countries

    May 12, 2026November 9, 2025 by TFE Times
  • Are Energy Gels Better Than Sports Drinks?

    May 11, 2026 by TFE Times
  • The Economies Most Dependent On Trade

    May 11, 2026November 9, 2025 by TFE Times
  • Mapped: Population Of Emerging Markets

    May 10, 2026November 9, 2025 by TFE Times
  • Legal Rules To Know Before Visiting Cannabis Stores In Illinois

    May 9, 2026 by TFE Times

Copyright © TFE Times, LLC. All Rights Reserved.

Terms of Service | Privacy Policy | Disclaimer

WordPress Theme : Eight Paper by 8Degree Themes