I've just started learning C and I'm trying to get used to the syntax, so when I try to run the program and enter the value it doesn't return anything. I don't know what I did wrong. Can anyone help me please?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char pass[10]; //max length of the string;
do{
printf("enter your password: \n");
scanf("%s",pass);
}while(strcmp(pass,'*') != 0); //checks if strings are equal
printf("%s",pass);
}
In C, single quotes are used for character constants. So '*'
is not a string containing the character *
but only the character *
.
To specify a string, use double quotes.
}while(strcmp(pass,"*") != 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.