I am new on C
Please guide me how to fix the problem "Segmentation fault"
Thank you
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define BUF_SIZE 1024
char *domainsplit(char *fdomain) {
int strlen_buf;
int i;
int dot;
char *domain;
unsigned char tmp_buf[BUF_SIZE];
strlen_buf = strlen(fdomain);
tmp_buf[strlen_buf] = '\0';
strcpy(tmp_buf, fdomain);
for (i = 0; i < strlen_buf; i++) {
tmp_buf[i] = tolower(tmp_buf[i]);
}
dot = 0;
for (i = strlen_buf - 1; i >= 0; i--)
if ((tmp_buf[i] == '.') &&
((dot > 0) ||
((strlen_buf - i) > 3)) &&
(++dot >= 2))
break;
sprintf(domain,"%s", (dot >= 2) ? (tmp_buf + i + 1) : tmp_buf);
return domain;
}
int main(void) {
char *txt;
txt = domainsplit("43476347.www.blahblah.com");
// show return blahblah.com
printf("%s",txt);
return(0);
}