C++
  Home arrow C++ arrow Page 2 - Programming in C
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Programming in C
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 35
    2005-10-27

    Table of Contents:
  • Programming in C
  • Creating Your First Program
  • Editing Your First Program
  • Dissecting a Simple Program
  • The Body of a Function
  • Developing Programs in C
  • Functions and Modular Programming
  • Common Mistakes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programming in C - Creating Your First Program


    (Page 2 of 8 )

    It’s time to create your first program. Let’s step through the processes of creating a simple C program, from entering the program itself to executing the program. Don’t worry if what you type doesn’t mean anything to you at this stage—I’ll explain everything as we go along.


    Figure 1-1.  Creating and executing a program

    ......................................................................................... 

    Try It Out: An Example C Program

    Run your editor and type in the following program exactly as it’s written. Be careful to input the punctuation exactly as you see here. The brackets used on the fourth and last lines are braces—the curly ones {}, not the square ones[]or the round ones()—it really does matter. Also, make sure you put the slashes the right way (/), as later you’ll be using the backslash (\) as well. Don’t forget the semicolon (;).

    Run your editor and type in the following program exactly as it’s written. Be careful to input the punctuation exactly as you see here. The brackets used on the fourth and last lines are braces—the curly ones {}, not the square ones [] or the round ones ()—it really does matter. Also, make sure you put the slashes the right way (/), as later you’ll be using the backslash (\) as well. Don’t forget the semicolon (;).

    /* Program 1.1 Your Very First C Program - Displaying Hello World */
    #include <stdio.h>
    void main()
    {
      printf("Hello world");
    }

    When you’ve entered the preceding source code, save the program ashello.c. You can use whatever name you like instead ofhello, but the extension must be.c. This extension name is the common convention when you write C programs. The extension identifies the contents of the file as C source code. Most      compilers will expect the source file to have the extension.c, and if it doesn’t, the compiler may refuse to process it.

    Now you’re ready to compile your program. Exactly how you do this will depend upon which compiler you’re using. If your C compiler allows you to work in an IDE, then you should easily be able to find your way to a menu where you can select the Compile option. In UNIX, the command you would use iscc.

    Next, you’ll link all the pieces necessary to create an executable program. This will add in code from the standard libraries that your program needs. Once again, the precise way to do this will depend upon which compiler system you’re using. If you’re using UNIX, then append any modules that you need to include at the end of yourcccommand. In an IDE, you’ll find the Link option on one of the menus. Remember that many IDEs offer a Build option that will compile and link your program automatically. If you aren’t working in an IDE, you should again consult your documentation to find out what the command is to run the linker.

    Finally, you can execute your program. Remember that you can do this in several ways. There is the usual method of double-clicking the.exefile from Windows Explorer if you’re using Windows. You could also run your program from the command line. To do so, just start a command-line session, change the current directory to the one that contains the.exefile for your program, and then enter the program name to run it. Within an IDE, you’ll probably also have the option of running your program directly. Alternatively, there may be a Run menu that will compile, link, and execute the program in one go.


    NOTE 
    If you’re working in an IDE, you may need to use the Window menu to change to an Output window, where you can see the results of your program execution.

    If everything worked without producing any error messages, you’ve done it! This is your first program, and you should see the following message on the screen:

    ----------------------------------------------------------------------      Hello world
    ----------------------------------------------------------------------

     

    ........................................................................................

    More C++ Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Beginning C, third edition", published by...
       · I need a C program for character stuffing.
       · source code for characterstuffing in c
       · i want a program on character stuffing using files
     

    Buy this book now. This article is excerpted from the book Beginning C, third edition, written by Ivor Horton (Apress, 2004; ISBN: 1590592530). Check it out today at your favorite bookstore. Buy this book now.

    C++ ARTICLES

    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class
    - Iostream Library and Basic I/O in C++
    - Introduction to Streams







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT