Code in dev C++ da problem, but in another compiler it works

The code is stopping responding on the last run.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, 
system("pause") or input loop */

typedef struct Aluno {
    int ra;
    float nota[4];
    float notaS;
    float notaFinal;
    char NomeAluno[50];
    char situacao[10];
}Aluno;

void calcNota(Aluno *alunos);

void subsNota(Aluno *alunos);

void exibirNota(Aluno *alunos);

int qntdAlunos;

float calcMediaSala(Aluno *alunos);


int main() {
   char ch;
   Aluno *alunos;

   int i = 0, j;

   printf("Por favor, informe a quantidade de alunos: ");
   scanf_s("%d", &qntdAlunos);

   alunos = (Aluno*)malloc((qntdAlunos) * sizeof(int));


   /*LAÇO RESPONSÁVEL POR COLETAR DADOS DOS ALUNOS, DE ACORDO COM A 
   QUANTIDADE INFORMADA*/

   while(i < qntdAlunos){
        rewind(stdin);

        printf("Nome do aluno(a): ");
        gets(alunos[i].NomeAluno);

        fflush(stdin);

        printf("RA: ");
        scanf_s("%i", &alunos[i].ra);

        for (j = 0; j < 4; j++)
        {
            printf("Nota %i: ", (j+1));
            scanf_s("%f", &alunos[i].nota[j]);
        }

        printf("Nota Substituta: ");
        scanf_s("%f", &alunos[i].notaS);

        printf("\n");
        i++;
   }

   subsNota(alunos);
   calcNota(alunos);
   exibirNota(alunos);

   printf("Media da sala: %.2f", calcMediaSala(alunos));

   return 0;
}

void calcNota(Aluno *alunos) {
    int i = 0;

    while (i < qntdAlunos) {
        alunos[i].notaFinal = ((alunos[i].nota[0] * 1) +      (alunos[i].nota[1] * 2) + (alunos[i].nota[2] * 3) + (alunos[i].nota[3] * 4)) / 10;
        if(alunos[i].notaFinal >= 5)
            strcpy(alunos[i].situacao,"Aprovado");
        else
            strcpy(alunos[i].situacao,"Reprovado");
        i++;
    }
}

void subsNota(Aluno *alunos) {
    int posAux, i = 0, j;
    float menorNota = 0;

    while (i < qntdAlunos) {
        for (j = 0; j <= 3; j++) {
            if (menorNota == 0) {
                menorNota = alunos[i].nota[j];
                posAux = 0;
            }
            else
            {
                if (alunos[i].nota[j] < menorNota) 
                {
                    menorNota = alunos[i].nota[j];
                    posAux = i;
                }
            }
        }
        if(menorNota < alunos[i].notaS)
        alunos[i].nota[posAux] = alunos[i].notaS;

        menorNota = 0;

       i++;
   }
}

void exibirNota(Aluno *alunos) {
    int i = 0, j;

    printf("========Notas finais dos alunos\n\n\n========");
    while (i < qntdAlunos) {
        printf("===================================\n");
        printf("Nome: %s\n", alunos[i].NomeAluno);
        printf("Ra: %i\n", alunos[i].ra);

        for (j = 0; j <= 3; j++) 
            printf("Nota %i:  %.2f\n", (j + 1), alunos[i].nota[j]);

        printf("Nota Substituta: %.2f\n", alunos[i].notaS);
        printf("Media do aluno: %.2f\n", alunos[i].notaFinal);
        printf("Situacao: %s\n", alunos[i].situacao);   
        printf("===================================\n\n");
        i++;
    }
}

float calcMediaSala(Aluno *alunos) {
    float notaTotalAlunos = 0, mediaSala;
    int i = 0;

    while (i < qntdAlunos) {
        notaTotalAlunos += alunos[i].notaFinal;
        i++;
    }
    mediaSala = notaTotalAlunos / qntdAlunos;
    return mediaSala;
}
 0
Author: Marlon Saldanha, 2016-11-30

1 answers

Since your school asked you to run in Devc MU change the build settings to be compiled in VS, your school asked the IDE and not the specific compiler; D

 1
Author: Higor Alves, 2016-11-30 19:21:25