Code Examples
  Home arrow Code Examples arrow Programming in C
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
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? 
CODE EXAMPLES

Programming in C
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2005-03-02

    Table of Contents:
  • Programming in C
  • Linking
  • Try It Out: An Example C Program
  • Dealing with Errors
  • Keywords
  • Developing Programs in C
  • Functions and Modular Programming
  • Try It Out: Exercising What You Know
  • 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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Programming in C
    (Page 1 of 9 )

    Programming in C is not difficult, despite what you may have heard. Read on to start learning how to program in this powerful language. This article is excerpted from the book Beginning C, written by Ivor Horton (Apress, 2004; ISBN 1590592530).

    C IS A POWERFUL AND COMPACT computer language that allows you to write programs that specify exactly what you want your computer to do. You’re in charge: you create a program, which is just a set of instructions, and your computer will follow those instructions.

    Programming in C isn’t difficult, as you’re about to find out. I’m going to teach you all the fundamentals of C programming in an enjoyable and easy-to-understand way, and by the end of this chapter, you’ll have written your first few C programs. It’s as easy as that!

    In this chapter you’ll learn

    • How to create C programs

    • How C programs are organized

    • How to write your own program to display text on the screen

    Creating C Programs

    There are four fundamental stages, or processes, in the creation of any C program:

    • Editing

    • Compiling

    • Linking

    • Executing

    You’ll soon know all these processes like the back of your hand (you’ll be doing them so easily and so often), but first let’s consider what each process is and how it contributes to the creation of a C program.

    Editing

    This is the process of creating and editing C source code—the name given to the program instructions you write. Some C compilers come with a specific editor that can provide a lot of assistance in managing your programs. In fact, an editor often provides a complete environment for writing, managing, developing, and testing your programs. This is sometimes called an integrated development environment, or IDE.

    You can also use other editors to create your source files, but they must store the code as plain text without any extra formatting data embedded in it. In general, if you have a compiler system with an editor included, then it will provide a lot of features that make it easier to write and organize your source programs. There will usually be automatic facilities for laying out the program text appropriately and color highlighting for important language elements, which not only makes your code more readable, but also provides a clear indicator when you make errors in keying in such words.

    If you’re working in UNIX, then the most common text editor is the vi editor. Alternately, you might prefer to use the emacs editor.

    From a PC, you could use one the many freeware and shareware programming editors. These will often provide a lot of help in ensuring your code is correct with syntax highlighting and autoindenting of your code. Don’t use word processors such as Microsoft Word, as they aren’t suitable for producing program code.

    Compiling

    The compiler converts your source code into machine language, and detects and reports errors in the compilation process. The input to this stage is the file you produced during your editing, which is usually referred to as a source file.

    The compiler can detect a wide range of errors that are due to invalid or unrecognized program code, as well as structural errors where, for example, part of a program can never be executed. The output from the compiler is known as object code and is stored in files called object files, which usually have names with the extension .obj. The compiler can detect several different kinds of errors during the translation process, and most of these will prevent the object file from being created.

    NOTE In UNIX, object files have the extension .o.

    The result of a successful compilation is a file with the same name that you used for the source file, but with the .obj extension.

    If you’re working in UNIX, then the standard command to compile your C programs will be cc. You can use it like this:

    cc -c myprog.c

    where myprog.c is the program you want to compile. Note that if you omit the -o flag, your program will automatically be linked as well. If you’re using the GNU’s Not UNIX (GNU) compiler, you should type

    gcc -c myprog.c.

    The result of a successful compilation will be an object file.

    Most C compilers will have a standard compile option, whether it’s from the command line (such as cc myprog.c) or a menu option from within an IDE (where you’ll find a Compile menu option). 

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

    More Code Examples Articles
    More By Apress Publishing


       · Has anyone looked over this article before posting? Both command line examples and...
       · The code was correct, the CMS's editor converted the <stdio.h> into HTML and erased...
     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway