Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(){
- char uname, passwd;
- printf("Enter your username: ");
- scanf("%c", uname);
- printf("Enter your password: ");
- scanf("%c", passwd);
- printf(" n");
- if (uname == "waw" && passwd == "wow"){
- printf("You have logged inn");
- } else {
- printf("Failed, please try againn");
- }
- return 0;
- }
- log.c: In function ‘main’:
- log.c:7:10: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
- scanf("%c", uname);
- ^
- log.c:9:10: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
- scanf("%c", passwd);
- ^
- log.c:13:14: warning: comparison between pointer and integer
- if (uname == "waw" && passwd == "wow"){
- ^
- log.c:13:33: warning: comparison between pointer and integer
- if (uname == "waw" && passwd == "wow"){
- ^
- #include <stdio.h>
- int main(){
- int res;
- char uname[40]; // char arrays instead of single char
- char passwd[40];
- printf("Enter your username: ");
- res = scanf("%39s", uname); // Set a maximum number of chars to read to avoid overflow
- if (res != 1) exit(1); // Error on stdin
- printf("Enter your password: ");
- res = scanf("%39s", passwd);
- if (res != 1) exit(1); // Error on stdin
- printf(" n");
- // Use strcmp
- if ((strcmp(uname, "waw") == 0) && (strcmp(passwd, "wow") == 0)){
- printf("You have logged inn");
- } else{
- printf("Failed, please try againn");
- }
- return 0;
- }
- char *uname, *passwd;
- uname = malloc(X); //where X is the number of bytes you want to allocate for uname
- if (uname == NULL)
- printf ("Error allocating memory for uname.");
- passwd = malloc(Y); //where Y is the number of bytes you want to allocate for passwd
- if (passwd == NULL)
- printf ("Error allocating memory for passwd.");
- #define MAX_LENGTH_UNAME X //where X is the maximum length for uname, for instance 25
- #define MAX_LENGTH_PASS Y //where Y is the maximum length for passwd, for instance 20
- ....
- char [MAX_LENGTH_UNAME] uname;
- char [MAX_LENGTH_PASS] passwd;
- scanf("%s", uname);
- scanf("%s", passwd);
- if ( (strcmp(uname, "waw") == 0) && (strcmp(passwd, "wow") == 0) ) {
- printf("You have logged inn");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement