Hi... i have a little problem on my code...
HI open a txt that have this:
LEI;7671;Maria Albertina da silva;
[email protected];
9;8;12;9;12;11;6;15;7;11;
LTCGM;6567;Artur Pereira Ribeiro;
[email protected];
6;13;14;12;11;16;14;
LEI;7701;Ana Maria Carvalho;
[email protected];
8;13;11;7;14;12;11;16;14;
LEI, LTCGM are the college;
7671, 6567, 7701 is student number;
Maria, Artur e Ana are the students name;
[email protected], ...@gmail are emails from students;
the first number of every line is the total of classes that students have;
after that is students school notes;
example:
College: LEI
Number: 7671
Name: Maria Albertina da Silva
email:
[email protected]
total of classes: 9
Classe Notes: 8 12 9 12 11 6 15 7 11.
My code:
typedef struct aluno{
char sigla[5];//college
char numero[80];//number
char nome[80];//student name
char email[20];//email
int total_notas;// total of classes
char tot_not[40]; // total classes
char notas[20];// classe notes
int nota; //class notes
char situacao[80]; //situation (aproved or disaproved)
}ALUNO;
void ordena(ALUNO*alunos, int tam)//bubble sort
{
int i=0;
int j=0;
char temp[100];
for( i=0;i<tam;i++)
for(j=0;j<tam-1;j++)
if(strcmp( alunos[i].sigla[j], alunos[i].sigla[j+1])>0){
strcpy(temp, alunos[i].sigla[j]);
strcpy(alunos[i].sigla[j],alunos[i].sigla[j+1]);
strcpy(alunos[i].sigla[j+1], temp);
}
}
void xml(ALUNO*alunos, int tam){
FILE *fp;
char linha[60];//line
int soma, max,
min, count;//biggest note and lowest note and students per course count
float media; //media of notes
fp=fopen("example.txt","r");
if(fp==NULL){
exit(1);
}
else{
while(!(feof(fp))){
soma=0;
media=0;
max=0;
min=0;
count=0;
fgets(linha,60,fp);
if(linha[0]=='L'){
if(ap_dados=strtok(linha,";")){
strcpy(alunos[i].sigla,ap_dados);//copy to struct
// i need to call bubble sort here, but i don't know how
printf("College: %s\n",alunos[i].sigla);
if(ap_dados=strtok(NULL,";")){
strcpy(alunos[i].numero,ap_dados);//copy to struct
printf("number: %s\n",alunos[i].numero);
if(ap_dados=strtok(NULL,";")){
strcpy(alunos[i].nome, ap_dados);//copy to struct
printf("name: %s\n",alunos[i].nome);
if(ap_dados=strtok(NULL,";")){
strcpy(alunos[i].email, ap_dados);//copy to struct
printf("email: %s\n",alunos[i].email);
}
}
}
}i++;
}
if(isdigit(linha[0])){
if(info_notas=strtok(linha,";")){
strcpy(alunos[i].tot_not,info_notas);
alunos[i].total_notas=atoi(alunos[i].tot_not);//total classes
for(z=0;z<=alunos[i].total_notas;z++){
if(info_notas=strtok(NULL,";")){
strcpy(alunos[i].notas,info_notas);
alunos[i].nota=atoi(alunos[i].notas); // student class notes
}
soma=soma + alunos[i].nota;
media=soma/alunos[i].total_notas;//doesn't work
if(alunos[i].nota>max){
max=alunos[i].nota;;//doesn't work
}
else{
if(min<alunos[i].nota){
min=alunos[i].nota;;//doesn't work
}
}
//now i need to count the numbers of students in the same college, but doesn't work
/*If(strcmp(alunos[i].sigla, alunos[i+1].sigla)=0){
count ++;
printf("%d\n", count); here for LEI should appear 2 students and for LTCGM appear 1, don't work
}*/
//Now i need to see if student is aproved or disaproved
// Student is disaproved if he gets 3 notes under 10, how can i do that?
}
printf("media %d\n",media); //media
printf("Nota maxima %d\n",max);// biggest note
printf("Nota minima %d\n",min); //lowest note
}i++;
}
}
}
fclose(fp);
}
int main(int argc, char *argv[]){
ALUNO alunos;
FILE *fp;
int tam;
fp=fopen(nomeFicheiro,"r");
alunos = (ALUNO*) calloc (tam, sizeof(ALUNO));
xml(alunos,nomeFicheiro, tam);
system("PAUSE");
return 0;
}