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
  • 25
  • 38
StackUser
  • 1,530
  • 3
  • 13
  • 17

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,846
  • 6
  • 41
  • 73