I searched all the web but I haven't come to a real solution (maybe I haven't googled the right words, I don't know). but here we are: this is my first C project with structs, and I tried to use gets and puts to overcome the printf-scanf's problem with white spaces, but the gets led to a lot of problems (the program skipped directly to the puts, without the gets) so I come in a topic of another guest of this forum where was mentioned
scanf("%[^\n]",str);
I applied this to my code, but I get the same problem, and I have also tried
scanf("%[^\n]s",str);
scanf("%[^\n]",&str); //despite looked senseless to me
I had read about fgets and fscanf, but I'm on an earlier phase
Here is the code... I use Visual Studio 2015, running on Windows 10.
#include <stdio.h>
#include <string.h>
typedef struct s_libro {
char titolo[50];
char autore[50];
char editore[20];
int pagine;
int costo$;
}t_libro;
int main() {
t_libro libro1;
t_libro libro2;
printf("Inserire autore(max 50) ,titolo(max 50) , editore(max 20), pagine, costo$\n");
//LIBRO 1
printf("\nLIBRO 1\n");
printf("\nInserisci il nome dell'autore del libro1 : \n");
scanf("%[^\n]", libro1.autore);
printf("\nInserire titolo del libro1 : \n");
scanf("%[^\n]", libro1.titolo);
printf("\nInserire nome dell'editore del libro1:\n");
scanf("%[^\n]", libro1.editore);
printf("\nInserire numero di pagine del libro1 : \n");
scanf("%d", &libro1.pagine);
printf("\nInserire il costo (dato numerico) del libro1 : \n");
scanf("%d", &libro1.costo$);
printf("\nLIBRO1\t");
printf("\nTitolo Libro1\t %s", libro1.titolo);
printf("\nAutore Libro1\t %s", libro1.autore);
printf("\nPagine Libro1\t %d", libro1.pagine);
printf("\nEditore Libro1\t %s", libro1.editore);
printf("\nCosto Libro1\t %d $", libro1.costo$);
printf("\n\n");
//LIBRO 2
printf("\nLIBRO 2\n");
printf("\nInserisci il nome dell'autore del libro2 : ");
scanf("%[^\n]", &libro2.autore);
printf("\nInserire il titolo del libro2 : ");
scanf("%[^\n]", &libro2.titolo);
printf("\nInserire L'editore del libro2:");
scanf("%[^\n]", libro2.editore);
printf("\nInserire il numero di pagine del libro2 : ");
scanf("%d", &libro2.pagine);
printf("\nInserire il costo (dato numerico) del libro2 : ");
scanf("%d", &libro2.costo$);
printf("\nLIBRO2\t");
printf("\nTitolo Libro2\t %s", libro2.titolo);
printf("\nAutore Libro2\t %s", libro2.autore);
printf("\nPagine Libro2\t %d", libro2.pagine);
printf("\nEditore Libro2\t %s", libro2.editore);
printf("\nCosto Libro2\t %d $", libro2.costo$);
printf("\n\n");
}