1

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?

Itban Saeed
  • 1,660
  • 5
  • 24
  • 35
StackUser
  • 1,410
  • 2
  • 11
  • 16

1 Answers1

4

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.

Cacho Santa
  • 6,668
  • 5
  • 37
  • 70