#include <stdio.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int enterAddress(struct in_addr* in)
{
	char buffer[32];
	int i= 0;
	memset(in, 0, sizeof(*in));
    printf("Enter the IP address: ");
	do {
		int ch= getchar();
		if (ch == EOF) {
			return 0;
		}
		buffer[i]= ch;
		if (ch != '\n') {
			printf("%c", buffer[i]);
		}
		fflush(stdout);
	} while (buffer[i] > 0 && buffer[i] != '\n' && ++i < sizeof(buffer)-1);
	buffer[i]= 0;
	printf("\n");
	
	if (inet_aton(buffer, in) == -1) {
		return 0;
	}
	// Here you could check that IP is not 0.0.0.0
	return i > 0;
}

void printAddress(struct in_addr* in) 
{
    printf("You entered IP address: %s\n\n\n", inet_ntoa(*in));
}

int main(void) 
{
	struct in_addr dir;
	
	while (enterAddress(&dir)) {
		printAddress(&dir);
	}

	// your code goes here
	return 0;
}
