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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -