string - Why will this simple C program not run? -


this code not run. can tell me why?

#include <stdio.h> #include <string.h> main (){     char user[7];       printf("username\n");     scanf("%s",user);     if(user == 'admin'){         printf("hello world");     }else{         printf("bad");     }     return(0); } 

this working example. need use strcmp compare strings. strcmp() returns 0, if strings equal.
if max input length known, should use length specifier in scanf or 1 of suggestion listed here, prevent buffer overflow.

#include <stdio.h> #include <string.h>  int main(int argc, char* argv) {     char user[7];       printf("username:\n");     scanf("%6s", user);      if(!strcmp(user, "admin"))     {         printf("hello world");     }     else     {         printf("bad");     }      return 0; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -