lundi 11 octobre 2021

in c language ask the user for his name , if the name is in the DB ,print “welcome (name)”, if not print “name isn't in DB

I wrote the code below in c language but the problem is that (if) always gives me false

char DB[][50]={"ahmed alla","Shady Ibrahim","Sara Sedky","Mohamed Ezz"};
    char name[50];
    fgets(name,50,stdin);
    int flag=1;
    for(int i=0;i<4;i++)
    {
        if(name==DB[i])
        {
            flag=0;
            printf("welcome %s \n",name);
        }
    }
    if(flag)
    {
        printf("sorry your name is not in the DB!");
    }

it always prints "sorry your name is not in the DB!" whatever the name is

Aucun commentaire:

Enregistrer un commentaire