Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<windows.h>
- //#include <curses.h>
- #include<conio.h>
- #define MAX 200
- typedef struct cel{
- int cod;
- char nome[MAX];
- char cc[MAX];
- char date[MAX];
- struct cel *prox;
- }celula;
- celula *ini = NULL;
- void imprima( )
- {
- system("cls");
- celula *p;
- if (ini == NULL)
- {
- printf("\nLista vazia.\n");
- getch();
- return;
- }
- printf("\n Itens na lista: ");
- for (p = ini; p != NULL; p = p->prox)
- printf( "%d ", p->cod);
- printf("%s",p->nome);
- printf("%s",p->cc);
- printf("%s",p->date);
- getchar();
- system("cls");
- }
- celula *busca(celula *ini)
- {
- system("cls");
- int x=0;
- celula *p;
- printf("numero");
- scanf("%d",&x);
- p = ini->prox;
- while (p != NULL && p->cod != x)
- p=p->prox;
- return p;
- }
- void insere()
- {
- int x;
- // char *nome[MAX]
- celula *nova = (celula*)malloc (sizeof (celula));
- system("cls");
- //Nome estava declarado como nome(MAX)
- printf("numero: ");
- scanf("%d",&x);
- nova->cod = x;
- printf("nome:");
- scanf("%s",nova->nome);
- printf("Cartão de Cidadão:");
- scanf("%s",nova->cc);
- printf("data:");
- scanf("%s",nova->date);
- nova->prox = ini;
- ini = nova;
- printf("numero %d inserido.\n",x);
- getchar();
- system("cls");
- system("cls");
- }
- //Conflito com remove da biblioteca stdio.h (http://www.tutorialspoint.com/c_standard_library/c_function_remove.htm)
- void remove_cel()
- {
- if (ini == NULL)
- {
- printf("\nLista vazia. Sem itens para remover.\n");
- getch();
- return;
- }
- else
- {
- celula *remove = ini;
- ini = remove->prox;
- printf("\nitem %d removido.\n",remove->cod);
- free(remove);
- getchar();
- }
- }
- void menu() {
- // system("cls");
- printf(" Menu ");
- printf("\n*********************************");
- printf("\n* 1-Inserir *");
- printf("\n* 2-Listar *");
- printf("\n* 3-buscar *");
- printf("\n* 4-remove *");
- printf("\n* 5-alterar *");
- printf("\n* 6-inserir no fim *");
- printf("\n* 0-sair *");
- printf("\n*********************************\n");
- printf("Entre com a opcao desejada: ");
- }
- int main(){
- char op;
- do {
- menu();
- op=getchar();
- switch(op) {
- case '1': insere();
- break;
- case '2': imprima();
- break;
- case '3': busca(ini);
- break;
- case '4': remove_cel();
- break;
- }
- } while (op != '0');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement