BrainDump
  Home arrow BrainDump arrow Page 2 - C: For Beginners
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
BRAINDUMP

C: For Beginners
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 7
    2008-01-28

    Table of Contents:
  • C: For Beginners
  • Insert Obligatory First Program Here
  • Working with Numbers
  • Putting on the Puts()

  • 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


    C: For Beginners - Insert Obligatory First Program Here


    (Page 2 of 4 )

    Writers that create books and articles for programmers believe that programmers are trained monkeys, obsessed with one goal: to say "Hello" to the world. They always give you these dumbassed introduction programs to print out "Hello World" to the screen. We're not going to do that though.

    (Note: Interestingly enough, the tradition of using "Hello World" as a programming introduction was started by Kernighan in his 1972 book Tutorial Introduction to the Language B and was inherited from an internal memo by the same author from Programming In C: A Tutorial).


    #include <stdio.h>

    int main (void)

    {

    printf("Why does every programmer look like this...n");

    printf(" ~~n");

    printf("c00cn");

    printf(" (0)n");

    printf(" Vn");

    return 0;

    }

    Before I explain the above code, let me show you the result:

      Why does every programmer look like this...

       ~~

     c00c

      (0)

       V

    You have no idea how long that took me to make. He looks a little bit like Dilbert, right? Anyway, here is how the program works:

    The first part of our code tells the compiler to include a file named stdio.h. This file is made up of descriptions of input/output functions and is used when writing output and accepting input from a user.

    The next part is the int main(void). This is required in every C program. The int part tells the compiler that an integer will be returned to whatever made the function itself run when it is finished. The main is a function, and the void in the parentheses states that there will be no parameters in main. As a beginner, it's okay if you don't understand any of that. We will cover it more in depth in future articles. For now, just know that every C program you create must have int main(void) in it.

    The printf is a function (it is defined in the stdio.h file, and that is why we had to include it) that prints text to the monitor. The words in between the parentheses and the double quotes will be printed to the monitor. And we use the semi-colon to end the line.

    Also, you will note the n. This is known as an escape and it tells the program to add a new line at the end of the sentence (or wherever you place it). If we write the following code without the escape...


    #include <stdio.h>

    int main (void)

    {

    printf("Why does every programmer look like this...");

    printf("ooga booga");

    return 0;

    }

    ...then our result would be:

      Why does every programmer look like this...ooga booga

    However, if we had included the n escape, like so:


    #include <stdio.h>

    int main (void)

    {

    printf("Why does every programmer look like this...n");

    printf("ooga booga");

    return 0;

    }

    The result would be:

      Why does every programmer look like this...

      ooga booga

    There are other escape methods, such as the t, which creates a tab, but we will go over those later.

    Lastly, the line return 0 literally returns the value 0 to the operating system. This tells the operating system that the program ran with no errors. If the value was anything but a zero, it would have indicated an error or a warning.

    So there you have it, your first C program.

    More BrainDump Articles
    More By James Payne


       · Thanks for dropping by to read my article on Beginning program in C, where we cover...
     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek