-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20 - Struct.c
60 lines (56 loc) · 1.63 KB
/
20 - Struct.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <locale.h>
struct {
char nome[25];
struct {
int qtd;
char nome[100];
} ingredientes[100];
}receitas[5];
void main(){
setlocale(LC_ALL,"portuguese");
int ingre,i, decisao, j, a;
printf("\n***Alô novamente!***\n");
printf("Este é seu livro de receitas\n");
printf("Insirá 5 receitas em seu livro\n");
for ( i = 0; i < 2; i++)
{
ingre=0;
a=1;
setbuf (stdin,NULL);
printf("%d - Receita\n",i+1);
printf("Nome da receita\n:>");
fgets(receitas[i].nome, 24, stdin);
setbuf (stdin,NULL);
printf("\n*Ingredientes*\n");
while (a==1){
setbuf(stdin,NULL);
printf("Nome do ingrediente\n:>");
fgets(receitas[i].ingredientes[ingre].nome, 99, stdin);
setbuf (stdin,NULL);
printf("Quantidade\n:>");
scanf("%d",&receitas[i].ingredientes[ingre].qtd);
setbuf(stdin,NULL);
printf("Cadastrar outro ingrediente? (1 - sim / 2 - não)\n:>");
scanf("%d",&decisao);
ingre++;
if(decisao == 2){
a=2;
}
}
printf("\n---Próxima---\n");
}
printf("\nAs receitas deste livro são:\n");
for (i = 0; i < 2; i++)
{
printf("Nome da Receita: %s",receitas[i].nome);
printf("Ingredientes:\n");
for ( j = 0; j < strlen(receitas[i].ingredientes)+1; j++)
{
printf("%d de %s", receitas[i].ingredientes[j].qtd, receitas[i].ingredientes[j].nome);
}
printf("\n-----------\n");
}
printf("\n--- Até a próxima receita :) ---\n");
return 0;
}