Xcode, #include stdio.h

I was starting to learn C language, but I failed immediately on the simplest most basic order, http://imgur.com/Jff6bcF . Can you check this out and point out my possible mistakes?

You’re entering C code into a playground. That won’t work because playgrounds only support Swift. You need to do one of two things:

  • use Swift instead of Objective-C, in which case you can continue using playgrounds

  • create an Xcode project (File > New > Project) from an appropriate template and then work from there

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you. Yes I started a project OS X > application > command line tools, with C as its' language. However how to view my program? Not in the compiler, in the actual program?

#include <stdio.h>

/ include a header which contains different comments; stdio.h contains printf and getchar*/

int main()

/ tell the compiler there is main function and the function return the integer int*/

{

printf( "I am alive! Beware.\n" );

/ standard C way of displaying output on the screen*/

/ The '\n' sequence is actually treated as a single character that stands for a newline*/

getchar();

/ reads in a single character and waits for the user to hit enter before reading the character */

return 0;

/ return a value from main to the operating system by using the return statement. This return value is important as it can be used to tell the operating system whether our program succeeded or not */

}


If i click on the file, I shouldve get a text "I am alive! Beware." in an application form right?

Command-line tools are executed in terminal.

if you double-click such command-line tool, OS X would open Terminal app for you and exectue your program in it, you should see your output in Terminal window.

Command-line tools are executed in terminal.

Indeed. Or you can choose Product > Run in Xcode to run it from within Xcode, in which case your see the output in the debug area (if it’s not visible, choose View > Debug Area > Show Debug Area to show it).

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Xcode, #include stdio.h
 
 
Q