Sorry if this sounds stupid, but I want to be able to input a struct, then put that struct into an array slot. Like, "input the data, put it into array slot 1, then another set of inputs into array slot 2" and so on.
(Btw, I'm aware of the whole 'gets() is obsolete' thing, but the thing I'm using, Dev-C++, uses it just fine.)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct res{
char nome[40];
char endereco[100];
char pedido[200];
char valor[20];
};
int main(int argc, char * argv[])
{
char M[100];
int c = 1;
int c2;
int menu;
int cod = 0;
while (cod < 100){
cod = cod + 1;
struct res R1, R2, R3, R4;
system("cls");
printf("Digite seu nome: \n");
gets(R1.nome);
fflush(stdin);
printf("Digite seu endereco: \n");
gets(R2.endereco);
fflush(stdin);
printf("Digite seu pedido: \n");
gets(R3.pedido);
fflush(stdin);
printf("Digite o valor total que vai pagar: \n");
gets(R4.valor);
fflush(stdin);
system("cls");
printf("============================\n");
printf("Codigo: %d\n", c);
printf("Nome: %s\n", R1.nome);
printf("Endereco: %s\n", R2.endereco);
printf("Pedido: %s\n", R3.pedido);
printf("Valor: %s\n", R4.valor);
system("pause");
system("cls");
printf("Escolha uma opcao\n");
printf("1 - Cadastrar pedido\n");
printf("2 - Consultar pedido\n");
printf("3 - Emitir relatorio\n");
printf("4 - Sair\n");
scanf("%d", &menu);
fflush(stdin);
switch (menu){
case 1:
c = c + 1;
break;
case 2:
system("cls");
printf("Digite o codigo: \n");
scanf("%d", &c2);
fflush(stdin);
if(c2 = c){
}
else{
printf("Codigo nao encontrado");
}
break;
case 3:
break;
case 4:
return 0;
default:
printf("Opcao invalido");
system("pause");
}
}
return 0;
}
Hope this makes some sense. Thanks in advance.
EDIT: I probably should've mentioned that this is just for a college project, nothing too major. So I don't think attacks are a factor here.