C++
  Home arrow C++ arrow Page 8 - 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  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
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 / 34
    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
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database 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 - Common Mistakes


    (Page 8 of 8 )

    Mistakes are a fact of life. When you write a computer program in C, the compiler must convert your source code to machine code, so there must be some very strict rules governing how you use the language. Leave out a comma where one is expected, or add a semicolon where you shouldn’t, and the compiler won’t be able to translate your program into machine code.

    You’ll be surprised just how easy it is to introduce typographical errors into a program, even after years of practice. If you’re lucky, these errors will be picked up when you compile or link your program. If you’re really unlucky, they can result in your program apparently working fine but producing some intermittent erratic behavior. You can end up spending a lot of time tracking these errors down.

    Of course, it’s not only typographical errors that cause problems. You’ll often find that your detailed implementation is just not right. Where you’re dealing with complicated decisions in your program, it’s easy to get the logic wrong. Your program may be quite accurate from a language point of view, and it may compile and run without a problem, but it won’t produce the right answers. These kinds of errors can be the most difficult to find.

    Points to Remember

    It would be a good idea to review what you’ve gleaned from your first program. You can do this by looking at the overview of the important points in Figure 1-4.

    Summary

    You’ve reached the end of the first chapter, and you’ve already written a few programs in C. You’ve covered quite a lot of ground, but at a fairly gentle pace. The aim of this chapter was to introduce a few basic ideas rather than teach you a lot about the C programming language. You should be confident about editing, compiling, and running your programs. You probably have only a vague idea about how to construct a C program at this point. It will become much clearer when you’ve learned a bit more about C and written some programs with more meat to them.

    In the next chapter, you’ll move on to more complicated things than just producing text output using theprintf()function. You’ll manipulate information and get some rather more interesting results. And by the way, theprintf()function does a whole lot more than just display text strings—as you’ll see soon.

    Exercises

    The following exercises enable you to try out what you’ve learned in this chapter. If you get stuck, look back over the chapter for help. If you’re still stuck, you can download the solutions from the Downloads area of the Apress website (http://www.apress.com), but that really should be a last resort.


    Figure 1-4.  Elements of a simple program

    Exercise 1-1. Write a program that will output your name and address using a separate printf()statement for each line of output.

    Exercise 1-2. Modify your solution for the previous exercise so that it produces all the output using only one printf() statement.

    Exercise 1-3. Write a program to output the following text, exactly as it appears here:

    --------------------------------------------------
    "It's freezing in here,"  he said coldly.
    --------------------------------------------------


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Beginning C, third edition", published by...
       · I need a C program for character stuffing.
     

    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

    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection
    - Temporary Variables: Chasing Temporaries Away
    - Temporary Variables: Temporaries Are Not Nec...
    - Temporary Variables: Keep Your Values Close,...


    Iron Speed





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