Medium

An email address such as "John.Smith@example.com" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com").

The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses.

Given a valid email address, find its domain part.

Example

  • For address = "prettyandsimple@example.com", the output should be
    findEmailDomain(address) = "example.com";
  • For address = "fully-qualified-domain@codesignal.com", the output should be
    findEmailDomain(address) = "codesignal.com".

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] string address

    Guaranteed constraints:
    10 ≤ address.length ≤ 50.

  • [output] string

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

char *findEmailDomain(char *address)
{
	for(int i=strlen(address)-1;;i--)
		if(address[i-1]=='@')
			return address+i;
}
728x90

+ Recent posts