C scaning input strings saves to wrong variable : I'm trying to scan 3 strings on the console in C with scanf, but every time the second string is scanned it will also be added at the end of the first one.

I already tried to change the scanf format parameter (%8s, %[^\n]s, %8[^\n]s) but nothing worked that well. It seems that %8s ignores the second scanf and jumps directly to the third one.

    char matrikelnumber[S_MATRIKELNUMBER]; //S_MATRIKELNUMBER is 8
    char first_name[S_FIRST_NAME]; //S_FIRST_NAME is 30
    char last_name[S_LAST_NAME]; //S_LAST_NAME is 30

    printf("Matrikelnummer: ");
    scanf("%s", matrikelnumber);

    printf("%s\n", matrikelnumber); //Prints the correct input

    printf("Vorname: ");
    scanf("%s", first_name);

    printf("%s\n", matrikelnumber); //Prints matrikelnumber + first_name added at the end

    printf("Nachname: ");
    scanf("%s", last_name);

How can I save all 3 strings correctly in the corresponding variable?

