-1

I am trying to learn Objective-C and the book i am learning from presents some code for me to type into Xcode. I keep receiving warnings on the scanf function for incorrect format specifiers even though this is how it is typed in the book. The code is as follows

@autoreleasepool {

    double value1 = 0.0, value2 = 0.0;

    char operator = '\0';


    scanf("%lf %c %lf", value1, operator, value2);

    }
Jack Bonneman
  • 1,821
  • 18
  • 24
rishaan
  • 1
  • 2
  • The build warning should tell you what's wrong and Xcode will often offer to fix it for you if you tap the build warning. – Wain Jul 08 '13 at 16:54
  • 1
    No, this is not how it's typed in the book. `scanf()` needs to modify its arguments - now think about how it will be possible. Or read some sample code using `scanf()`. –  Jul 08 '13 at 16:54

1 Answers1

1

If you haven't studied pointers probably you'll see it later: to modify a variable you need it's address , otherwise you don't modify the original value, but just a copy. So scanf expects pointers as arguments:

scanf("%lf %c %lf", &value1, &operator, &value2);
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187