Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------LISTA DISCIPLINAS--------------------
- typedef struct disciplina
- {
- Texto nome;
- LAlunos *la;
- LPerguntas *lp;
- }Disciplina;
- typedef struct ndisciplina
- {
- Disciplina *Info;
- struct ndisciplina *prox;
- }NDisciplina;
- typedef struct ldisciplinas
- {
- NDisciplina *Inicio;
- int Nel;
- }LDisciplinas;
- //........
- Disciplina *InicDisp(LDisciplinas *LD)
- {
- Texto t = (Texto)malloc(sizeof(char));
- int n;
- printf("\nIntroduza o nome da disciplina:");
- fflush(stdin);
- gets(t);
- NDisciplina *ND = LD->Inicio, *Aux = NULL;
- bool test = false;
- for(int i = 0; i<LD->Nel; i++)
- {
- if(stricmp(ND->Info->nome, t) == 0)
- {
- test = true;
- break;
- }
- Aux = ND;
- ND = ND->prox;
- }
- if(test) return ND->Info;
- printf("\nIntroduziu como nome da disciplina \"%s\" que não existe ainda.\nDeseja criar esta disciplina?", t);
- printf("\n1 = Sim | 2 = Não\n");
- while(scanf("%d", &n) != 1 || (n < 1 || n > 2))
- {
- while((getchar()) != '\n');
- printf("\nApenas 1 ou 2!\n");
- printf("\nIntroduziu como nome da disciplina \"%s\" que não existe ainda.\nDeseja criar esta disciplina?", t);
- printf("\n1 = Sim | 2 = Não\n");
- }
- if(n == 1)
- {
- if(!Aux)
- {
- LD->Inicio = CND();
- LD->Nel = 1;
- ND = LD->Inicio;
- ND->Info = ID();
- sprintf(LD->Inicio->Info->nome, "%s", t);
- ND->Info->la = CLA();
- ND->Info->lp = CLP();
- }
- else
- {
- LD->Nel++;
- Aux->prox = CND();
- ND = Aux->prox;
- ND->Info = ID();
- sprintf(ND->Info->nome, "%s", t);
- ND->Info->la = CLA();
- ND->Info->lp = CLP();
- }
- GuardarNomeDiciplinas(LD);
- return ND->Info;
- }
- else
- return InicDisp(LD);
- //SaveSubjects(LD);
- }
- //..................
- void CarregarNomeDisciplinas(LDisciplinas *LD)
- {
- if(!fexist(DIS_PATH))
- LD->Nel = 0;
- else
- {
- FILE *f = fopen(DIS_PATH, "r");
- Texto t = (Texto)malloc(MAX_TEXTO);
- fgets(t, MAX_TEXTO, f);
- sscanf(t, "%d", &LD->Nel);
- LD->Inicio = CND();
- NDisciplina *ND = LD->Inicio;
- for(int i=0; i < LD->Nel; i++)
- {
- ND->Info = ID();
- fgets(t, MAX_TEXTO, f);
- ND->Info->nome = (Texto)realloc(t, strlen(t)+1);
- ND->prox = CND();
- ND = ND->prox;
- }
- }
- }
- void GuardarNomeDiciplinas(LDisciplinas *LD)
- {
- FILE *f = fopen(DIS_PATH, "w");
- fprintf(f,"%d", LD->Nel);
- NDisciplina *D = LD->Inicio;
- while(D)
- {
- fprintf(f, "\n%s", D->Info->nome);
- D = D->prox;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment