strcpy and strcat

Lab C Beginner 10 points

Read a first and last name. Build LAST, FIRST in a new buffer using strcpy and strcat, and print it with its length.

Input

Two words.

Output

Two lines.

Example

Input

Ada Lovelace

Output

Lovelace, Ada
13
Sample input available Sample output available
Editor
C

Hints

strcpy(dest, src) copies; strcat(dest, src) appends.

The destination must be big enough.

Solution explanation

You can't use = or + on C strings - use the string.h functions.

Show solution
#include <stdio.h>
#include <string.h>

int main() {
    char first[50], last[50], full[110];
    scanf("%s %s", first, last);
    strcpy(full, last);
    strcat(full, ", ");
    strcat(full, first);
    printf("%s\n%d\n", full, (int) strlen(full));
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD