Une erreur dans mon programme

Résolu
bonjour,
voici un programme en c que je veut compiler sur visual studio 2005
mon probléme est qu'il me donne une erreur que je ne sais pas résoudre pourriez- vous m'aider?
voici l'énoncé de l'erreur:
error c2664: 'strcmp':impossible de convertir le paramétre 1 de 'char(*_w64)[30]' en 'const char*'
ceci sur la ligne:
if (strcmp(&fiche.nom,&nom)==0)
comment puis-je m'en sortir sans tout modifier?

voici le programme:
Description:
Recherche d'une fiche dans le repertoire téléphonique*/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *fd;
struct enreg
{
char nom[30];
char tel[10];
};
int question(char*texte)
{
char getch();
char reponse=' ';
while (reponse!='o' && reponse!='n')
{
printf("%s",texte);
reponse=getch();
printf("\n");
if (reponse=='O') reponse='o';
if (reponse=='N') reponse='n';
if (reponse!='o' && reponse!='n')
printf("!!!repondre par O ou N!!!\n");
};
if (reponse=='o')
return 0;
else return -1;
}
void creation()
{
struct enreg fiche;
int reponse;
printf("...Creation d'une fiche...\n");
printf("Nom ? ");
scanf("%s",&fiche.nom);
printf("Numero de telephone ? ");
scanf("%s",&fiche.tel);
reponse=question("Enregistrer la fiche (O/N) ?");
if (reponse)return;
fseek(fd,0,2);
fprintf(fd,"%s%s\n",fiche.nom,fiche.tel);
}
int rechercher()
{
struct enreg fiche;
char nom[30];
int err;
int reponse;
printf("...rechercher une fiche...\n");
printf("nom a chercher ? ");
scanf("%s",&nom);
fseek(fd,0,0);
err=fscanf(fd,"%s %s",&fiche.nom,&fiche.tel);
while (err>0)
{
if (strcmp(&fiche.nom,&nom)==0)
{
printf("nom:%s telephone:%s\n",fiche.nom,fiche.tel);
reponse=question("continuer la recherche (O/N)?");
if (reponse)return 0;
}
err=fscanf(fd,"%s%s",&fiche.nom,&fiche.tel);
}
printf("fin du fichier, appuyer sur une touche...\n");
void getch();
}
int menu()
{
int choix=0;
while (choix<1 || choix>3)
{
printf("menu : \n");
printf("1 - creation d'une nouvelle fiche\n");
printf("2 - recherche d'une fiche\n");
printf("3 - quitter\n");
printf("votre choix ? ");
scanf("%i",&choix);
if (choix<1 || choix>3)
printf("!!!entrez 1, 2 ou 3 !!!\n");
}
return choix;
}
void main()
{
int choix=0;
fd=fopen("rep.dat","a+");
printf("...REPERTOIRE TELEPHONIQUE...\n");
while (choix!=3)
{
choix=menu();
switch (choix)
{
case 1 : creation();
break;
case 2 : rechercher();
break;
default : break;
}
}
fclose(fd);/*Fermeture du fichier*/
/*Fin*/
printf("Merci, et au revoir\n");
scanf("%i",&choix);
}
Configuration: Windows XP
Internet Explorer 6.0

5 réponses

  • Votes
  • Date
  • Date décroissante
  1. Modérateur
    Salut,
    char nom[30];
    
    scanf("%s",&nom);
    
    if (strcmp(&fiche.nom,&nom)==0) 
    je n'ai pas regardé tout le code attentivement
    toutefois j'ai remarqué des erreurs

    le nom d'un tableau et l'adresse de 1er élément donc pas besoin d'utiliser &
    tu dois écrire
    char nom[30];
    
    scanf("%s",nom);
    
    if (strcmp(fiche.nom,nom)==0) 
    1. Dans ta fonction rechercher(), essai de remplacer ca:
      if (strcmp(&fiche.nom,&nom)==0)
      par ça :
      if (strcmp(fiche.nom, nom)==0)
      1. mon amis ice que tu a un ps2 ou bien ps1 et dis moi ice que ce programme et tout les jour comme ca ou bien ta a déja travaile avec sur un n'autre pc et je peux t'aide bonne courage

        mohamed
        1. merci pour votre aide, j'ai ecrit la ligne suivante:
          if (strcmp(fiche.nom,nom)==0)
          mon programme c'est compilé avec 0 erreur mais m'a donné 2 erreurs à l'execution qui sont les suivantes:
          Erreur 1 error LNK2019: symbole externe non résolu "char __cdecl getch(void)" (?getch@@YADXZ) référencé dans la fonction "int __cdecl question(char *)" (?question@@YAHPAD@Z) rechercher.obj

          Erreur 2 fatal error LNK1120: 1 externes non résolus C:\Documents and Settings\Utilisateur1\Mes documents\Visual Studio 2005\Projects\Devoir N°7\Dev7exo4\Debug\Dev7exo4.exe 1
          1. Modérateur
            Salut,
            merci pour votre aide, j'ai ecrit la ligne suivante:
            if (strcmp(fiche.nom,nom)==0)


            ça ne suffit pas, lit mon message précédent
            d'ailleurs voici ton code un peu corrigé
            il fonctionne mais pas comment je crois que tu veux
            à revoir la fonction recherche - je ne pense pas que c'est ça que tu veux
            j'ai mis /* ici */ ou j'ai fait des modifs
            #include<stdio.h>
            #include<string.h>
            #include<stdlib.h>
            FILE *fd;
            struct enreg
            {
              char nom[30];
              char tel[10];
            };
            int question (char *texte)
            {
              char reponse = ' ';
              while (reponse != 'o' && reponse != 'n')
                {
                  printf ("%s", texte);
                  reponse = getchar ();     /* ici */
                  printf ("\n");
                  if (reponse == 'O')
                    reponse = 'o';
                  if (reponse == 'N')
                    reponse = 'n';
                  if (reponse != 'o' && reponse != 'n')
                    printf ("!!!repondre par O ou N!!!\n");
                };
              if (reponse == 'o')
                return 0;
              else
                return -1;
            }
            
            void creation ()
            {
              struct enreg fiche;
              int reponse;
              printf ("...Creation d'une fiche...\n");
              printf ("Nom ? ");
              scanf ("%s", fiche.nom);      /* ici */
              printf ("Numero de telephone ? ");
              scanf ("%s", fiche.tel);      /* ici */
              reponse = question ("Enregistrer la fiche (O/N) ?");
              if (reponse)
                return;
              fseek (fd, 0, 2);
              fprintf (fd, "%s%s\n", fiche.nom, fiche.tel);
            }
            
            int rechercher ()
            {
              struct enreg fiche;
              char nom[30];
              int err;
              int reponse;
              printf ("...rechercher une fiche...\n");
              printf ("nom a chercher ? ");
              scanf ("%s", nom);            /* ici */
              fseek (fd, 0, 0);
              err = fscanf (fd, "%s %s", fiche.nom, fiche.tel);     /* ici */
              while (err > 0)
                {
                  if (strcmp (fiche.nom, nom) == 0) /* ici */
                    {
                      printf ("nom:%s telephone:%s\n", fiche.nom, fiche.tel);
                      reponse = question ("continuer la recherche (O/N)?");
                      if (reponse)
                        return 0;
                    }
                  err = fscanf (fd, "%s%s", fiche.nom, fiche.tel);  /* ici */
                  return 1;                 /* ici */
                }
              printf ("fin du fichier, appuyer sur une touche...\n");
              getchar (); /* ici */
              return 1; /* ici */
            }
            
            int menu ()
            {
              int choix = 0;
              while (choix < 1 || choix > 3)
                {
                  printf ("menu : \n");
                  printf ("1 - creation d'une nouvelle fiche\n");
                  printf ("2 - recherche d'une fiche\n");
                  printf ("3 - quitter\n");
                  printf ("votre choix ? ");
                  scanf ("%i", &choix);
                  if (choix < 1 || choix > 3)
                    printf ("!!!entrez 1, 2 ou 3 !!!\n");
                }
              return choix;
            }
            
            int main ()  /* ici */
            {
              int choix = 0;
              fd = fopen ("rep.dat", "a+");
              printf ("...REPERTOIRE TELEPHONIQUE...\n");
              while (choix != 3)
                {
                  choix = menu ();
                  switch (choix)
                    {
                    case 1:
                      creation ();
                      break;
                    case 2:
                      rechercher ();
                      break;
                    default:
                      break;
                    }
                }
              fclose (fd);                  /*Fermeture du fichier */
              /*Fin */
              printf ("Merci, et au revoir\n");
              /*scanf("%i",&choix); plus besoin, tu viens de dire Merci, et au revoir :-))  - ICI*/
              return 0;   /* ici */
            }
            
            je l'ai compilé sur
            Debian GNU/Linux lenny/sid
            gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
            Copyright (C) 2006 Free Software Foundation, Inc.
            This is free software; see the source for copying conditions.  There is NO
            warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
            
            et je n'ai pas eu des erreurs