Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char name[25];
    char surname[25];
    File* F = fopen("string test.txt","w");

    if(F == NULL)
    {
         printf ("Error Creating File. ");
         exit(1);
     }

     printf("Enter name: ");
     fgets(name,24,stdin);

     printf("Enter surname: ');
     fgets(surname,24,stdin);

     //Here's the first problem:
     printf("\n\nName is: %s and Surname is: %s",name,surname);

    //Here's the second problem
    fprintf(F,"Name :%s and Surname :%s",name,surname);

    fclose(F);

    return 0;

}
After running the above code, I enter name "dog laptop" and Surname "hen pen" (without quotes).

In file and on console, I get output:

Name is: dog laptop
and Surname is: hen pen

My question is why did the cursor go to next line where as I didn't include a new line character?? And how to prevent this.