I know that there are already a few questions similar to this one but I'm truly not getting what I'm doing wrong in my case.
I have to collect 5 variables, 3 are strings that can be more than one word, and the other 2 are intergers.
This is for a program that I need to turn in and the input need to be exactly like I posted below.
I also need to specifically use sscanf and fgets and not scanf or getchar().
int main()
{
char linha[200];
char * nome;
char * autor;
char * genero;
char anoChar[200];
int * ano;
char duracaoChar[200];
int * duracao;
printf(">");
fgets(linha, sizeof linha, stdin);
sscanf(linha, "%[^\n]", nome);
fgets(linha, sizeof linha, stdin);
sscanf(linha, "%[^\n]", autor);
fgets(linha, sizeof linha, stdin);
sscanf(linha, "%[^\n]", genero);
fgets(linha, sizeof linha, stdin);
sscanf(linha, "%[^\n]", anoChar);
*ano=atoi(anoChar);
fgets(linha, sizeof linha, stdin);
sscanf(linha, "%[^\n]", duracaoChar);
*duracao=atoi(duracaoChar);
printf("%s %s %s %d %d", nome, autor, genero, ano, duracao);
return 0;
}
I've tried putting on the input per example:
Dreams
Singer
pop
1970
10
But it will stop reading on "Dreams" and just close the program