c - Program cannot match datas in variables -


this question has answer here:

this part of 'phonebook' program.

void viewone(){       char name[25], fname[25];      int n, ncheck, op;      fp = fopen("phonebook.txt","r");      printf ("\n search : \n 1: name\n 2: phone number\n");     printf ("enter option : ");     scanf ("%d",&op);      switch(op){          case 1:             printf ("\n enter name : ");             scanf ("%s",name);              fscanf(fp, "%s %d", fname, &ncheck);              while (!feof(fp)){                  printf ("\n\n %s \n\n",fname);                  if (fname == name){              \\ problem in here                      printf ("\n\n contact found...\n");                      printf (" %s +880%d", fname, ncheck);                      break;                  }                  else{                      fscanf(fp, "%s %d", fname, &ncheck);                  }                  if (feof(fp)){                      printf ("\n\n contact not found...\n\n");                  }              }              menu();              break;          case 2:              printf ("\n\n enter contact number (+880) : ");             scanf ("%d",&n);              fscanf(fp, "%s %d", fname, &ncheck);              while (!feof(fp)){                  if (ncheck == n){                      printf ("\n\n contact found...\n");                      printf (" %s +880%d\n", fname, ncheck);                      break;                  }                  else{                      fscanf(fp, "%s %d", fname, &ncheck);                  }                  if (feof(fp)){                      printf ("\n\n contact not found...\n\n");                  }              }              menu();              break;          default:              printf ("\n wrong option...\n\n");              viewone();              break;         }      } 

when comes marked line, program should search file 'fname' character until matches 'name' character. though match, nothing happens , program still goes on. , in end, told in else statement. question why happening , how can fix it?

my program runs when search phone number. why not happening character?

comparing string not done ==. instead use string compare function this

strcmp(fname,name) 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -