C cannot figure out if statement -


this question has answer here:

so trying learn c can't figure out why code won't run properly.

#include <stdio.h> #include <stdlib.h>  int main() {     char username[25];     char myname[25] = "myname";      printf("please enter name: \n");     scanf("%s", username);      if(username == myname)     {         printf("congratulations name myname!!!");     }     else     {         printf("your name %s how disappointing...", username);     }       return 0; } 

the problem if statement never seems return true. can me this?

this line comparing locations of strings, different, since comparing 2 different strings.

if(username == myname) 

the correct test in c use library function.

#include <string.h> ... if(strcmp(username,myname) == 0) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -