Hi
I've got a strange problem that i'm going to explain but before, here is my code:
/!\ This is not my finished application /!\

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

struct Date {
            short Jour;
            short Mois;
            short Annee;
            };
struct Ouvriers {
            char Genre;
            long NumRegistre;
            char Nom[25];
            char Prenom[30];
            char Rue[50];
            int CodePostal;
            char Ville[20];
            char Specialite[20];
            struct Date DateNaiss;
            struct Date DateEngag;
                };
void AfficheOuvri(struct Ouvriers[], int);
int EncodeOuvri(struct Ouvriers[], int);
main ()
{
    struct Ouvriers Personne[100];
    int nOuvrier = 0;
    int nFemme;
    int nHomme;
    int Out;
    int Ret;
    int i;
    long NumReg[100];
    int Index[100];
    char Data[100][56];

    do
    {
        nOuvrier = 0;
        Out = 0;
        Ret = EncodeOuvri(Personne, i);
        if(Ret == 0)
        {
            Out = 1;
        }
        nOuvrier++;
    }while(Out != 1);

    system("cls");

    for(i = 0; i < nOuvrier; i++)
    {
        AfficheOuvri(Personne, i);
    }



}
int EncodeOuvri(struct Ouvriers Personne[], int i)
{
    int Etat = 0;

    printf("\n\nEncoder le genre: ");
    fflush(stdin);
    Personne->Genre=getchar();
    if(Personne->Genre != '\n')
    {
        printf("\nEncoder le numero de registre: ");
        fflush(stdin);
        scanf("%d", &Personne->NumRegistre);
        printf("\nEntrez votre nom: ");
        fflush(stdin);
        scanf("%s", &Personne->Nom);
        printf("\nEntrez votre prenom: ");
        fflush(stdin);
        scanf("%s", &Personne->Prenom);
        printf("\nNom de rue: ");
        fflush(stdin);
        scanf("%s", &Personne->Rue);
        printf("\nCode postal: ");
        fflush(stdin);
        scanf("%d", &Personne->CodePostal);
        printf("\nVille: ");
        fflush(stdin);
        scanf("%s", &Personne->Ville);
        printf("\nSpecialite: ");
        printf("\n\t1. Coffreur");
        printf("\n\t2. Ferrailleur");
        printf("\n\t3. Couvreur");
        printf("\n\t4. Menuisier");
        printf("\n\t5. Macon");
        printf("\n\t6. Manoeuvre");
        printf("\n\t7. Grutier\n");
        printf("Votre choix: ");
        fflush(stdin);
        scanf("%d", &Personne->Specialite);
        printf("\n\n\n");
        Etat = 1;
    }
    return Etat;

}
void AfficheOuvri(struct Ouvriers Personne[], int i)
{


    printf("\nGenre: %c", Personne->Genre);
    printf("\nNumero de Registre: %d", Personne->NumRegistre);
    printf("\nNom: %s", Personne->Nom);
    printf("\nPrenom: %s", Personne->Prenom);
    printf("\nRue: %s", Personne->Rue);
    printf("\nCode postal: %d", Personne->CodePostal);
    printf("\nVille: %s", Personne->Ville);

}

So I explain a little bit because it's in french.
I've go to make a programm for a work construction.
I've got to register worker and then printf them, and here is my problem.
Register worker is okey but when i've got printf them there is a little bug:
Gender(Genre) has always nothing to prinft, i've tried with getchar scanf and no matter...

Sorry for my bad english. :)

Recommended Answers

All 3 Replies

When you pass a character array to scanf, you don't have to use the address of operator because the array name is the address of the array..Also the main function should be defined returning an int and i is used uninitialized on line line 41.

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

struct Date {
            short Jour;
            short Mois;
            short Annee;
            };
struct Ouvriers {
            char Genre;
            long NumRegistre;
            char Nom[25];
            char Prenom[30];
            char Rue[50];
            int CodePostal;
            char Ville[20];
            char Specialite[20];
            struct Date DateNaiss;
            struct Date DateEngag;
                };
void AfficheOuvri(struct Ouvriers[], int);
int EncodeOuvri(struct Ouvriers[], int);
int main ()
{
    struct Ouvriers Personne[100];
    int nOuvrier = 0;
    int nFemme;
    int nHomme;
    int Out;
    int Ret;
    int i;
    long NumReg[100];
    int Index[100];
    char Data[100][56];

    do
    {
        nOuvrier = 0;
        Out = 0;
        Ret = EncodeOuvri(Personne, i);
        if(Ret == 0)
        {
            Out = 1;
        }
        nOuvrier++;
    }while(Out != 1);


    for(i = 0; i < nOuvrier; i++)
    {
        AfficheOuvri(Personne, i);
    }

return 0;

}
int EncodeOuvri(struct Ouvriers Personne[], int i)
{
    int Etat = 0;

    printf("\n\nEncoder le genre: ");
    fflush(stdin);
    Personne->Genre=getchar();
    if(Personne->Genre != '\n')
    {
        printf("\nEncoder le numero de registre: ");
        fflush(stdin);
        scanf("%ld", &Personne->NumRegistre);
        printf("\nEntrez votre nom: ");
        fflush(stdin);
        scanf("%s", Personne->Nom);
        printf("\nEntrez votre prenom: ");
        fflush(stdin);
        scanf("%s", Personne->Prenom);
        printf("\nNom de rue: ");
        fflush(stdin);
        scanf("%s", Personne->Rue);
        printf("\nCode postal: ");
        fflush(stdin);
        scanf("%d", &Personne->CodePostal);
        printf("\nVille: ");
        fflush(stdin);
        scanf("%s", Personne->Ville);
        printf("\nSpecialite: ");
        printf("\n\t1. Coffreur");
        printf("\n\t2. Ferrailleur");
        printf("\n\t3. Couvreur");
        printf("\n\t4. Menuisier");
        printf("\n\t5. Macon");
        printf("\n\t6. Manoeuvre");
        printf("\n\t7. Grutier\n");
        printf("Votre choix: ");
        fflush(stdin);
        scanf("%s", Personne->Specialite);
        printf("\n\n\n");
        Etat = 1;
    }
    return Etat;

}
void AfficheOuvri(struct Ouvriers Personne[], int i)
{


    printf("\nGenre: %c", Personne->Genre);
    printf("\nNumero de Registre: %ld", Personne->NumRegistre);
    printf("\nNom: %s", Personne->Nom);
    printf("\nPrenom: %s", Personne->Prenom);
    printf("\nRue: %s", Personne->Rue);
    printf("\nCode postal: %d", Personne->CodePostal);
    printf("\nVille: %s", Personne->Ville);

}

When I compile your code is still not working, try.
In fact we must register worker and when we want to stop we must use ENTER when programm ask the user Gender, and then we have to see all worker that have been registered and here is my problem there isn't always gender. (genre)

I've retype all my code and then the problem gone...
Strange...
'll call Sherlock Holmes next time, it'll be faster.

thanks gerard4143

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.