Given below is a piece of code that does not do what I want
do
{
printf("inserisci un nome: ");
scanf("%29s", s);
} while (s!="*");
My aim is to exit from the cycle if the string entered is "*". Why doesn't it work? What should I modify?
Given below is a piece of code that does not do what I want
do
{
printf("inserisci un nome: ");
scanf("%29s", s);
} while (s!="*");
My aim is to exit from the cycle if the string entered is "*". Why doesn't it work? What should I modify?
Take a look at strcmp to compare strings, !=
will not do what you want.
In that case !=
will compare the variable s
(a pointer to the first element of the array s
) with the string "*"
. That is why it was not working properly.