please verify the code
- From: "Roman Mashak" <mrv@xxxxxxxx>
- Date: Sat, 17 Dec 2005 14:00:26 +0700
Hello, All!
I wrote function parsing the fully-quilified domain name and extracting
'host' and 'domain' parts seperately. The important thing for me is to keep
original string (pointed by 'fqdn' in function). Is my way of coding
correct, is there a way to optimize function and make it not so clumsy (I
like the code produced by K&R in their famous book: brief, clear,
comprehensible, nothing superfluous :) ).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFLEN 1024
static int
parse_fqdn(char *fqdn, char *host, char *domain)
{
char p[BUFLEN], *s;
strcpy(p, fqdn);
if ( (s = strstr(p, ".")) ) {
*s = '\0';
strcpy(host, p);
strcpy(domain, ++s);
return 0;
}
else
return -1;
}
int main(void)
{
char dom[] = "www.my.example.dom.ain";
char h[BUFLEN], d[BUFLEN];
if ( parse_fqdn(dom, h, d) == 0 )
printf("fqdn='%s'\nhostname='%s', domain name='%s'\n", dom, h, d);
return 0;
}
Thanks in advance
With best regards, Roman Mashak. E-mail: mrv@xxxxxxxx
.
- Follow-Ups:
- Re: please verify the code
- From: websnarf
- Re: please verify the code
- From: pete
- Re: please verify the code
- From: Thomas Matthews
- Re: please verify the code
- Prev by Date: Re: suggestion for writing a program to concatanate two strings
- Next by Date: Re: Why is there no difference between buffered and unbuffered file IO?
- Previous by thread: Newbie question
- Next by thread: Re: please verify the code
- Index(es):