2 Replies - 226 Views - Last Post: 09 November 2019 - 12:09 PM Rate Topic: -----

#1 AMG_9980   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-November 19

problème

Posted 09 November 2019 - 03:41 AM

Bonjour j'ai une problème dans un programme je vous demande de m'aider:
voilà le prog je veux afficher ces deux taches:
(Afficher les étudiants admet
Afficher les étudiants d'une filiairexxw)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct date_Nais
{
    int J;
    int M;
    int A;
}date_Nais;

typedef struct ETUDIANT
{
    char nom[10],prenom[10],ville[100];
    int ID;
    float moy;
    date_Nais dtn;
}ETUDIANT;

int main()
{
    ETUDIANT E1[100];
    date_Nais dn;
    int ch,ne,i,n;
    char rep,n1,n2;
printf("MENU GENERAL : \n");
printf("1-	ajouter un etudiant \n");
printf("2-	afficher un etudiant(id) \n");
printf("3-	ajouter plusieurs etudiants\n");
printf("4-	recherche d un etudiants(id) \n");
printf("5-	recherche d un etudiants(nom) \n");
printf("6-	recherche d un etudiants(prenom) \n");
printf("7-	Afficher les etudiants admet \n");
printf("8-	trier les etudiants selon la moyenne \n");
printf("7-	quitter\n");

do
{

printf("entrez votre choix : ");
scanf("%d",&ch);
switch(ch){
case 1:
        printf(" AJOUTER UN ETUDIANT\n");
        printf("======================\n");
        printf("donnez l\'\ ID de l\'\etudiant : ");
    scanf("%d",&E1[i].ID);
        printf("donnez le nom de l\'\etudiant : ");
    scanf("%s",E1[i].nom);
        printf("donnez le prenom  de l\'\etudiant : ");
    scanf("%s",E1[i].prenom);
        printf("donnez le jour de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.J);
        printf("donnez le mois de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.M);
        printf("donnez l\'\annee de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.A);
        printf("donnez la ville  de l\'\etudiant : ");
    scanf("%s",E1[i].ville);
    printf("donnez la moyenne de l\'\etudiant : ");
    scanf("%f",&E1[i].moy);
    break;
case 2:
    printf("\n AFFICHER UN ETUDIANT\n");
    printf("======================\n");
    printf("ID\t\t nom\t\t prenom\t\t dtns\t\t ville\t\t moyenne\n");
    printf("%d\t\t %s\t\t %s\t\t %d/%d/%d\t %s\t\t%f\t\t ",E1[i].ID,E1[i].nom,E1[i].prenom,E1[i].dtn.J,E1[i].dtn.M,E1[i].dtn.A,E1[i].ville,E1[i].moy);
break;
case 3:
    printf(" AJOUTER PLUSIEUR ETUDIANTS\n");
    printf("============================\n");
    printf("le nbre des etudiants a ajouter");
    scanf("%d",&ne);
    for(i=1;i<=ne;i++)
    {
                printf("donnez l\'\ ID de l\'\etudiant : ");
    scanf("%d",&E1[i].ID);
        printf("donnez le nom de l\'\etudiant : ");
    scanf("%s",E1[i].nom);
        printf("donnez le prenom  de l\'\etudiant : ");
    scanf("%s",E1[i].prenom);
        printf("donnez le jour de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.J);
        printf("donnez le mois de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.M);
        printf("donnez l\'\annee de l\'\etudiant : ");
    scanf("%d",&E1[i].dtn.A);
        printf("donnez la ville  de l\'\etudiant : ");
    scanf("%s",E1[i].ville);
    printf("donnez la moyenne de l\'\etudiant : ");
    scanf("%f",&E1[i].moy);
    }
    break;
case 4:
    printf("\n AFFICHER PLUSIEURS ETUDIANTS\n");
    printf("=================================\n");
    printf("ID\t\t nom\t\t prenom\t\t dtns\t\t ville\t\t moyenne\n");
    for (i=1;i<=ne;i++)
    {
        printf("%d\t\t %s\t\t %s\t\t %d/%d/%d\t %s\t\t%f\t\t ",E1[i].ID,E1[i].nom,E1[i].prenom,E1[i].dtn.J,E1[i].dtn.M,E1[i].dtn.A,E1[i].ville,E1[i].moy);
    }
break;
case 5:
    printf("\n RECHERCHE D UN ETUDIANT PAR ID\n");
    printf("===================================\n");
    printf("entre le numero de l etudiant : ");
    scanf("%d",&n);
    if (E1[i].ID==n)
    {
        printf("l etudiant n %d est %s %s",E1[i].ID,E1[i].nom,E1[i].nom);
    }
break;
case 6:
    printf("\n RECHERCHE D UN ETUDIANT PAR nom\n");
    printf("===================================\n");
    printf("entre le nom de l etudiant : ");
    scanf("%s",&n1);
    if (E1[i].nom=='n1')
    {
        printf("l etudiant %s a l identifiant : %d",E1[i].nom,E1[i].ID);
    }
break;
case 7:
    printf("\n RECHERCHE D UN ETUDIANT PAR nom\n");
    printf("===================================\n");
    printf("entre le nom de l etudiant : ");
    scanf("%s",&n2);
    if (E1[i].prenom=='n2')
    {
        printf("l etudiant %s a l identifiant : %d",E1[i].prenom,E1[i].ID);
    }
break;
case 8:
    printf("")
}
printf("\nvoulez vous continuez O/N : ");
scanf("%s",&rep);
}
while(rep=='o');
    return 0;
}


This post has been edited by Skydiver: 09 November 2019 - 12:09 PM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: problème

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: problème

Posted 09 November 2019 - 07:17 AM

Heads up this is a english primary language forum.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg   User is offline

  • member icon

Reputation: 5771
  • View blog
  • Posts: 17,667
  • Joined: 25-December 09

Re: problème

Posted 09 November 2019 - 12:09 PM

In future please use code tags!

:code:


Also your compiler should be complaining about several issues:

Quote

||=== Build: Debug in chomework (compiler: GCC 8-1) ===|
main.c||In function ‘main’:|
main.c|47|error: unknown escape sequence: '\040'|
main.c|47|error: non-ISO-standard escape sequence, '\e'|
main.c|49|error: non-ISO-standard escape sequence, '\e'|
main.c|51|error: non-ISO-standard escape sequence, '\e'|
main.c|53|error: non-ISO-standard escape sequence, '\e'|
main.c|55|error: non-ISO-standard escape sequence, '\e'|
main.c|57|error: non-ISO-standard escape sequence, '\e'|
main.c|59|error: non-ISO-standard escape sequence, '\e'|
main.c|61|error: non-ISO-standard escape sequence, '\e'|
main.c|77|error: unknown escape sequence: '\040'|
main.c|77|error: non-ISO-standard escape sequence, '\e'|
main.c|79|error: non-ISO-standard escape sequence, '\e'|
main.c|81|error: non-ISO-standard escape sequence, '\e'|
main.c|83|error: non-ISO-standard escape sequence, '\e'|
main.c|85|error: non-ISO-standard escape sequence, '\e'|
main.c|87|error: non-ISO-standard escape sequence, '\e'|
main.c|89|error: non-ISO-standard escape sequence, '\e'|
main.c|91|error: non-ISO-standard escape sequence, '\e'|
main.c|119|warning: multi-character character constant [-Wmultichar]|
main.c|119|error: comparison between pointer and integer|
main.c|129|warning: multi-character character constant [-Wmultichar]|
main.c|129|error: comparison between pointer and integer|
main.c|135|warning: zero-length gnu_printf format string [-Wformat-zero-length]|
main.c|135|error: expected ‘;’ before ‘}’ token|
main.c|42|warning: switch missing default case [-Wswitch-default]|
main.c|23|warning: unused variable ‘dn’ [-Wunused-variable]|
||=== Build failed: 21 error(s), 5 warning(s) (0 minute(s), 0 second(s)) ===|


The first several issues have to do with escaping "normal" characters like 'e'.

Next the first Non-escape sequence error:

Quote

main.c|119|warning: multi-character character constant [-Wmultichar]|

                if (E1[i].nom == 'n1')
                {


E1[i].nom is an array of char, 'n1' is a multi-character character constant (not allowed by the way) not an array. A character constant must consist of a single character 'n', by the way the single quotes tell the compiler it is a character constant, double quotes "N" denote a string const. And don't forget that you can't compare two arrays (C-strings) with the operator==, if you want to compare two arrays you must individually compare all the elements of the two arrays, to compare two C-string you need to use strcmp().

You really, Really, REALLY need to start using more meaningful variable and function names.

Lastly for now, be careful with scanf(), you need to insure that the format specifiers match the type of variable, for example:
                scanf("%s", &n1);


In the above n1 appears to be a single character while the "%s" specifier expects a C-string. Using an incorrect type for the specifier invokes undefined behavior.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1