Skip to content
TFE Times

TFE Times

Business, Technology, and Culture

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

Posted on September 1, 2017April 1, 2018
C_plus_plus_at_woodlands_school

C++: Split a string in C++

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

C++: Environment Variables

Posted on September 1, 2017April 1, 2018
Brandeis Business School
University of California Irvine Leaderboard
Click here
University of Maryland Masters of Economics Sideboard
NYU Tandon School of Engineering Sideboard
output_8BgzjE
University of Maryland Masters of Economics Sideboard
University of California Berkeley Master of Financial Engineering MFE Sideboard
  • Helium Reserves By Country

    April 23, 2026October 29, 2025 by TFE Times
  • Why Car Accident Claims Require Experienced Legal Representation

    April 22, 2026 by TFE Times
  • How do you choose a good payment gateway in India for your business?

    April 22, 2026 by TFE Times
  • 10 Tools That Make Gardening Cost-Effective in 2026

    April 22, 2026April 22, 2026 by TFE Times
  • Where Americans Spend The Most & Least On Groceries

    April 22, 2026October 28, 2025 by Patrick
  • States With The Most Job Openings

    April 21, 2026October 28, 2025 by TFE Times
  • A Decade Of Central Bank Gold Purchases

    April 20, 2026October 28, 2025 by TFE Times
  • Where The World’s Nuclear Power Comes From

    April 19, 2026October 28, 2025 by TFE Times
  • America’s Fastest Shrinking Jobs

    April 18, 2026October 28, 2025 by TFE Times
  • 6 Tools to Build a Practice That Runs Without You in 2026

    April 17, 2026 by TFE Times

Copyright © TFE Times, LLC. All Rights Reserved.

Terms of Service | Privacy Policy | Disclaimer

WordPress Theme : Eight Paper by 8Degree Themes