home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!news.ysu.edu!do-not-reply-to-path
- From: af458@yfn.ysu.edu (Jon K. Salmon)
- Subject: Re: gethostnamae(), novice question...
- Message-ID: <1992Jul26.024747.28685@news.ysu.edu>
- Sender: news@news.ysu.edu (Usenet News Admin)
- Nntp-Posting-Host: yfn
- Organization: Youngstown State University/Youngstown Free-Net
- Date: Sun, 26 Jul 1992 02:47:47 GMT
- Lines: 23
-
-
- > #include <stdio.h>
- >
- > main() {
- > char *host[64];
- > gethostname(host,sizeof host);
- > printf("%s\n",host);
- > }
-
- > This program gets the hostname as 'mercury.ncat.edu'. What's the decent
- > way/s to strip off the .ncat.edu part? I know how to do that by sed. The
- > solution should be general, I mean should be applicable to any hostname with
- > domain name in it.
-
- How about this:
-
- if (strchr(host,'.') != NULL)
- *(strchr(host,'.')) = 0x00;
-
- It will simply put a terminating null whereever the first
- period, if any, is.
-
- -- Jon
-