0

I am new to Objective C. But I know C/C++. I want to accept inputs from keyboard, let assume that its a program for adding 2 numbers.

So can I use scanf("%d %d",&a,&b); ?

sathya
  • 1,404
  • 2
  • 15
  • 26
Arun
  • 39
  • 1
  • 3
  • 9
  • If you are creating a command line util, yes you can. If it is a normal app, pls use the UI elements such as NSTextField to read he input. What exactly is your requirement? – Shanti K Apr 07 '14 at 09:39
  • @ Shanti K: The following is my code is this correct?#import int main () { /* variable definition: */ int a, b; int c; NSLog(@"Enter values for A & B: "); scanf("%d %d",&a,&b); c = a + b; NSLog(@"value of c : %d \n", c); return 0; } – Arun Apr 07 '14 at 09:42
  • Ok. can I install Objective C compiler in Windows 8? – Arun Apr 07 '14 at 09:49
  • http://stackoverflow.com/questions/19471448/objective-c-compiler-and-editor – Shanti K Apr 07 '14 at 09:50

2 Answers2

1

objective C is a superset of regular C , so you can use all the C functions like scanf() or getchar() and similar!

Leonardo Bernardini
  • 1,076
  • 13
  • 23
0

Yes you can. You can also rename yours file to .mm and write:

#include <iostream>
using namespace std;

cin>>a>>b;
Cy-4AH
  • 4,370
  • 2
  • 15
  • 22