Add to Google

Detailed C Beginner Tut - basis for learning any application programming language

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

Detailed C Beginner Tut - basis for learning any application programming language

AlanDS
QUOTE
The best way to learn programming is to dive right in and start writing real programs. This way, concepts which would otherwise seem abstract make sense, and the positive feedback you get from getting even a small program to work gives you a great incentive to improve it or write the next one.
Diving in with ``real'' programs right away has another advantage, if only pragmatic: if you're using a conventional compiler, you can't run a fragment of a program and see what it does; nothing will run until you have a complete (if tiny or trivial) program. You can't learn everything you'd need to write a complete program all at once, so you'll have to take some things ``on faith'' and parrot them in your first programs before you begin to understand them. (You can't learn to program just one expression or statement at a time any more than you can learn to speak a foreign language one word at a time. If all you know is a handful of words, you can't actually say anything: you also need to know something about the language's word order and grammar and sentence structure and declension of articles and verbs.)
Besides the occasional necessity to take things on faith, there is a more serious potential drawback of this ``dive in and program'' approach: it's a small step from learning-by-doing to learning-by-trial-and-error, and when you learn programming by trial-and-error, you can very easily learn many errors. When you're not sure whether something will work, or you're not even sure what you could use that might work, and you try something, and it does work, you do not have any guarantee that what you tried worked for the right reason. You might just have ``learned'' something that works only by accident or only on your compiler, and it may be very hard to un-learn it later, when it stops working.
Therefore, whenever you're not sure of something, be very careful before you go off and try it ``just to see if it will work.'' Of course, you can never be absolutely sure that something is going to work before you try it, otherwise we'd never have to try things. But you should have an expectation that something is going to work before you try it, and if you can't predict how to do something or whether something would work and find yourself having to determine it experimentally, make a note in your mind that whatever you've just learned (based on the outcome of the experiment) is suspect.
The first example program in K&R is the first example program in any language: print or display a simple string, and exit. Here is my version of K&R's ``hello, world'' program:
#include <stdio.h>
main()
{
printf("Hello, world!\n");
return 0;
}
If you have a C compiler, the first thing to do is figure out how to type this program in and compile it and run it and see where its output went. (If you don't have a C compiler yet, the first thing to do is to find one.)
The first line is practically boilerplate; it will appear in almost all programs we write. It asks that some definitions having to do with the ``Standard I/O Library'' be included in our program; these definitions are needed if we are to call the library function printf correctly.
The second line says that we are defining a function named main. Most of the time, we can name our functions anything we want, but the function name main is special: it is the function that will be ``called'' first when our program starts running. The empty pair of parentheses indicates that our main function accepts no arguments, that is, there isn't any information which needs to be passed in when the function is called.
The braces { and } surround a list of statements in C. Here, they surround the list of statements making up the function main.
The line
printf("Hello, world!\n");
is the first statement in the program. It asks that the function printf be called; printf is a library function which prints formatted output. The parentheses surround printf's argument list: the information which is handed to it which it should act on. The semicolon at the end of the line terminates the statement.
(printf's name reflects the fact that C was first developed when Teletypes and other printing terminals were still in widespread use. Today, of course, video displays are far more common. printf's ``prints'' to the standard output, that is, to the default location for program output to go. Nowadays, that's almost always a video screen or a window on that screen. If you do have a printer, you'll typically have to do something extra to get a program to print to it.)
printf's first (and, in this case, only) argument is the string which it should print. The string, enclosed in double quotes "", consists of the words ``Hello, world!'' followed by a special sequence: \n. In strings, any two-character sequence beginning with the backslash \ represents a single special character. The sequence \n represents the ``new line'' character, which prints a carriage return or line feed or whatever it takes to end one line of output and move down to the next. (This program only prints one line of output, but it's still important to terminate it.)
The second line in the main function is
return 0;
In general, a function may return a value to its caller, and main is no exception. When main returns (that is, reaches its end and stops functioning), the program is at its end, and the return value from main tells the operating system (or whatever invoked the program that main is the main function of) whether it succeeded or not. By convention, a return value of 0 indicates success.
This program may look so absolutely trivial that it seems as if it's not even worth typing it in and trying to run it, but doing so may be a big (and is certainly a vital) first hurdle. On an unfamiliar computer, it can be arbitrarily difficult to figure out how to enter a text file containing program source, or how to compile and link it, or how to invoke it, or what happened after (if?) it ran. The most experienced C programmers immediately go back to this one, simple program whenever they're trying out a new system or a new way of entering or building programs or a new way of printing output from within programs. As Kernighan and Ritchie say, everything else is comparatively easy.
How you compile and run this (or any) program is a function of the compiler and operating system you're using. The first step is to type it in, exactly as shown; this may involve using a text editor to create a file containing the program text. You'll have to give the file a name, and all C compilers (that I've ever heard of) require that files containing C source end with the extension .c. So you might place the program text in a file called hello.c.
The second step is to compile the program. (Strictly speaking, compilation consists of two steps, compilation proper followed by linking, but we can overlook this distinction at first, especially because the compiler often takes care of initiating the linking step automatically.) On many Unix systems, the command to compile a C program from a source file hello.c is
cc -o hello hello.c
You would type this command at the Unix shell prompt, and it requests that the cc (C compiler) program be run, placing its output (i.e. the new executable program it creates) in the file hello, and taking its input (i.e. the source code to be compiled) from the file hello.c.
The third step is to run (execute, invoke) the newly-built hello program. Again on a Unix system, this is done simply by typing the program's name:
hello
Depending on how your system is set up (in particular, on whether the current directory is searched for executables, based on the PATH variable), you may have to type
./hello
to indicate that the hello program is in the current directory (as opposed to some ``bin'' directory full of executable programs, elsewhere).
You may also have your choice of C compilers. On many Unix machines, the cc command is an older compiler which does not recognize modern, ANSI Standard C syntax. An old compiler will accept the simple programs we'll be starting with, but it will not accept most of our later programs. If you find yourself getting baffling compilation errors on programs which you've typed in exactly as they're shown, it probably indicates that you're using an older compiler. On many machines, another compiler called acc or gcc is available, and you'll want to use it, instead. (Both acc and gcc are typically invoked the same as cc; that is, the above cc command would instead be typed, say, gcc -o hello hello.c .)
(One final caveat about Unix systems: don't name your test programs test, because there's already a standard command called test, and you and the command interpreter will get badly confused if you try to replace the system's test command with your own, not least because your own almost certainly does something completely different.)
Under MS-DOS, the compilation procedure is quite similar. The name of the command you type will depend on your compiler (e.g. cl for the Microsoft C compiler, tc or bcc for Borland's Turbo C, etc.). You may have to manually perform the second, linking step, perhaps with a command named link or tlink. The executable file which the compiler/linker creates will have a name ending in .exe (or perhaps .com), but you can still invoke it by typing the base name (e.g. hello). See your compiler documentation for complete details; one of the manuals should contain a demonstration of how to enter, compile, and run a small program that prints some simple output, just as we're trying to describe here.
In an integrated or ``visual'' progamming environment, such as those on the Macintosh or under various versions of Microsoft Windows, the steps you take to enter, compile, and run a program are somewhat different (and, theoretically, simpler). Typically, there is a way to open a new source window, type source code into it, give it a file name, and add it to the program (or ``project'') you're building. If necessary, there will be a way to specify what other source files (or ``modules'') make up the program. Then, there's a button or menu selection which compiles and runs the program, all from within the programming environment. (There will also be a way to create a standalone executable file which you can run from outside the environment.) In a PC-compatible environment, you may have to choose between creating DOS programs or Windows programs. (If you have troubles pertaining to the printf function, try specifying a target environment of MS-DOS. Supposedly, some compilers which are targeted at Windows environments won't let you call printf, because until you call some fancier functions to request that a window be created, there's no window for printf to print to.) Again, check the introductory or tutorial manual that came with the programming package; it should walk you through the steps necessary to get your first program running

© ADS

Notice from BuffaloHELP:
Copied http://www.eskimo.com/~scs/cclass/notes/sx1a.html Use QUOTE when you've already published an article. Use CODE for all codes.

 

 

 


Reply

Dark_Prisoner
You must make your tuto attractive :
Remove the quotation box and put some colors than say that it is not your tuto
This is not clear at all !
Just a piece of advice. wink.gif

Reply

iGuest
C language basis
Detailed C Beginner Tut

I want basic about language C. I am student of bs computer science in university of gujrat pakistan. Sir kindly help me thanks

-question by Abdullah Ahmed

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. c language tutorial for beginner - 92.27 hr back. (1)
  2. c beginner - 112.73 hr back. (1)
  3. turbo c beginners tutorial - 123.33 hr back. (3)
  4. detailed c - 189.03 hr back. (1)
  5. turbo c tutorials beginner - 193.60 hr back. (1)
  6. show me a shell programming in unix for fibonacci series - 206.18 hr back. (1)
  7. turbo c/c language software download - 219.69 hr back. (1)
  8. turbo c tutorials - 243.58 hr back. (1)
  9. c programming - 376.27 hr back. (1)
  10. beginner text editor of c programming - 444.55 hr back. (1)
  11. detailed description of programming using functions in c - 532.89 hr back. (2)
  12. detailed c learning - 570.59 hr back. (1)
  13. turbo c tutorial - 603.22 hr back. (1)
  14. fibonacci c prog - 643.79 hr back. (1)
Similar Topics

Keywords : detailed beginner tut basis learning application programming

  1. Why Must We Learn Object Oriented Programming - help me to understand the benefit of OOP (8)
    As a software laboratory assistant, I teach the class of Object Oriented Programming. Everything
    went well until one day a student of mine ask me a simple problem like this Q/A: him : Why must we
    use Object oriented Programming? I thought the usual one could do almost everything. me : Well, in
    Object Oriented Programming we could make a class, so basically eveything could be made to an
    'object' in our mind. him : That's why I'm asking, why must we made everything an
    object? What's the difference? me : In Object Oriented Programming, Encapsulation ...
  2. Good Books On C++ Game Programming - I need some books! (3)
    I am looking for some good books on game programming in c++ if any body out there has any
    suggestions feel free to post them. Oh by the way should i start out with an easier language like
    BASIC or should I just work on c++. Ineed some help people please reply fast. Tahnx
    David H /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> ...
  3. Life In Programming? - wheres this headed? (12)
    Hey guys im 16 and really like programming (although im fairly new at it) ive already taken a year
    of basic html and what not. This year im taking a class in c++ and VB next year i hope to take java
    and php. However next year will be my senior year and i will have to start applying for colleges
    and im trying to convince my parents that there ARE jobs in computers its hard for them to do this
    they like to stay locked up in there own little world **cough cough** stone age **cough** so what i
    was wondering is what jobs are actually out there for this kinda stuff what are ...
  4. Finding The Rgb Color Of An Image - Using any programming language (4)
  5. C Programming Video Tutorials - This is for all the memebers out there looking or need some mroe help (3)
    Hello per this is for the memeber that want to start programming in " C "... C is a
    very powerful Programming Lang In fact mayb to powerful.. Well there is 138 Videos in the
    TUT.. I Have uploaded the it so per .rar is per chapter /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> P@ssword for ALL .rar files
    is : sid3arm chapter #1 = Introduction to C ** Download link ** chapter #2 = A
    basic C program ** Download link ** chapter #3 = Basic Elements of a C Program **
    Download link ...
  6. Alright, I'm Taking Computer Programming As A Class In School. - (10)
    Is there anything I should personally be worried about or anything I really need to know? I'm
    pretty much good with computers and such and pretty much spend my whole life on them, lol....
  7. Win32: Dialog Box And Accelerator - Win32 API programming (2)
    ok my problem is how do i make or assign a keyboard accelerator with modal dialog boxes since the
    message loop is inside the function call of DailogBox() functions, unlike the modeless dialog box in
    which you are the one who will create the message loop for the dialog box... is it even possible?...
  8. Opengl And Mfc Dialog Based Application - some comments about using it together (7)
    AS you probably know you can create a simple OpenGL applications using WinAPI functionality only
    (you can create it using Microsoft Visual Studio), but if you are making somethink with real windows
    interface and want to create application with multiple windows/dialogs/buttons with Windows Styles
    etc... you can use MFC (Microsoft Foundation Classes) to do it ... But i did a 2 hours web search to
    find example of using OpenGL windows inside MFC created Dialog window. I found it and want to share
    my results now. My application is a simple OpenGL based tool, which shows Ope...
  9. How Many of You Use the C Programming language? - (23)
    Just wanted to know how many of you are currently using C language for programming. If you can tell
    what sort of programs you do, it would be useful. ...
  10. A Question About C++ Programming Under Linux - (7)
    Hello guys! i prepare to develop under linux using c++, but i don't know what tools i should
    use...some one tell me to use vim, but i think vim is so hard to use!can u recommend me some ide???
    thank u very much...
  11. Let Me Teach You C++ - I would like teach u c++ if you are beginner. (10)
    As you know c++ is enhance version of c, we can say it is superset of c. The most important
    facilities that c++ adds on c++ on to c are classes, inheritance, function overloading and operator
    overloading. These features enable creating of abstract data types, inherit properties from existing
    data types and support polymorphism, thereby making c++ a truly object oriented language. Have a
    look of a basic c++ program - CODE #include int main() { cout return 0; } output- C++ is
    better than c. The header file iostream should be included at the beginning of all prog...
  12. D Programming Language - (9)
    hi friends, surprised... was that a type???? It is not a type... I know this is a C/C++
    programming language forum.. Just wanted to share something I came across today... A new
    programming language based on C and C++ is being developed.. It would have all the power of C/C++,
    in other words as the spec says "retains the ability to write high performance code and interface
    directly with the operating system API's and with hardware." The specification of the language
    and alpha phase compilers are available at www.digitalmars.com I just browsed throught the spec a...
  13. Discussion On Dynamic Programming - (3)
    Dynamic Programming is one of the powerful programming approach now a day. DP applicable when sub
    problems share sub sub problems. (No independent sub problems). Solve each sub problem once, save
    the answer, and when needed use the previously computed result. Like for Fibonacci series. To get
    f(n+1) we need addition of f(n), f(n-1) and for f(n) we need f(n-1), f(n-2). so to get f(n+1) we
    need f(n) and f(n-1) and again for f(n) we need f(n-1) and f(n-2). In this approach we are
    calculating same thing more then once . That is a very bad idea. But what if we store the data...
  14. Start Learning C/c++ - (8)
    I want to learn C/C++, i know some other languages such as some BASIC once and python, what should i
    download to get C/C++ is it Visual studio? and is that free and if possible could i get a link to
    the right 1.. i have looked on Google but there was to much stuff to pick from. also if you know nay
    good tutorials to learn the syntax of C/C++ i would like a link them as well. thanks...
  15. Vesa Programming Viewer In D O S - Graphics in C/C++ (3)
    Hello friends, I wanna make an image viewer in DOS...can any one help me how to deal with high
    resolution screens in DOS uning mouse using VESA interrupts. Please help.. thanks acumentech...
  16. Beginners Guide To C/c++ Programming? - (3)
    ok so I was wondering if anyone knows where I can find a good, c/c++ dummy friendly guide? my main
    reason for want to learn it so that I can make .cab files that do registry edits for ppc. I know
    this should be easy to do, Any help would be greatly appreciated. Thx in advanced, Mike...
  17. C Programming: Arrays - A Clear Description of Arrays (2)
    C programming provides a capability that enables a user to design a set of similar data types,
    called Arrays. For understanding the arrays properly, let us consider the following program CODE
    main() { int x; j=5 j=10; printf("\nj= %d",x); } No doubt, this program will print the value
    of j as 10. This is because when a value 10 is assigned to j, the earlier value of j, i.e. 5, is
    lost. Thus, ordinary variables are capable of holding only one value at a time. However, there are
    situations in which we would want to store more than one value at a time in a single ...
  18. C Or C++ Easy Programming Generator - You need a program? (6)
    Hi i just had a stupid question on how to program is C or C++. I would like to know if there is any
    program like Photoshop to create C codes or how to put them together. If someone could show me it
    would be great. I appreciate it as i love computers and want to be like a wiz at it and also
    everything related to it. I know that this is crazy and i have heard that from people they tell me
    you're a GFX person stay there but i want to explore. Thanks if helped....
  19. Dos Game Programming In C For Beginners - (1)
    There are a number of tutorials available for the intermediate game programmer, but there are very
    few good tutorials for beginners who have never drawn a pixel on the screen. A quick search on the
    net reveals hundreds of sites devoted to 3D, polygons, texture- mapping and other advance topics,
    but the beginner has no where to get started. This tutorial is for C programmers who want to get an
    introduction to game programming. find this tutorial at Dos Game Programming in C for Beginners
    ...
  20. Dos Programming, Undocumented Dos, And Dos Secrets - (3)
    This web site is devoted to DOS programming for those of us who still enjoy programming in DOS some
    of its containt are Disk/Files - Programming the disk and/or file info. DOS - DOS programs, DOS
    prompt, DOS compilers, etc. Encryption/Compression - Encryption and Compression. Games - Programming
    Games. Hardware/System programming - Memory, BIOS, CMOS, and other Hardware/System items.
    Input/Output Devices - Mice, Joystick, Keyboard, Modem, Printer, etc.. Misc - Item that don't
    fit in any/all the other subjects. Sound - Sound programming Video/Graphics - Graphics progr...
  21. C/c++ Programming Experince - How long does it take before programming useful programs? (3)
    I've been teaching my self C++, slowly but surely. Everything I try to program is just mediocre,
    and much simplier to use something already made. How long does it take before I can start
    programming useful decent programs?...
  22. 256-color Vga Programming In C Site - (0)
    what some say is the best VGA programming site on the web VGA Basics Setting the video mode,
    plotting a pixel, and mode 0x13 memory. Primitive Shapes & Lines Drawing lines, polygons,
    rectangles, and circles. Also, Bresenham's algorithm, fixed-point math and pre-computing tables.
    Bitmaps & Palette Manipulation The BMP file format, drawing bitmaps, and palette manipulation. Mouse
    Support & Animation Animation, mouse motion, and mouse button detection. Double Buffering, Page
    Flipping, & Unchained Mode Double buffering, page flipping, structure of unchained mode,...
  23. Programming A Malloc - (1)
    A little background about what I am doing is this: I have an array which holds a linked list
    containing the memory that is currently taken from the system. Each index I have like 16 size
    memory or less can be stored only in index 0, index 1 is for memory inbetween 16-32, index 2 is for
    memory inbetween 32-64, etc all the way up to 2048 which is the max allocatable memory. Now the way
    my malloc is to work is that it first will run through my list to see if any memory is available
    that is greater than or equal to the size I need, if there is any at all it will return it...
  24. Where To Start Learning C++ Programming Language - Resources for C++ (4)
    I'm planning on learning c++ but I'm having some problems. First, I need a compiler.
    I've downloaded Digital Mars (www.digitalmars.com) but how the heck do I compile something????
    There's this other free compiler that loooks great but seems hard to install. Does anyone know a
    good freeware compiler??? Also does anyone know what some good tutorial resources are? I've
    found a few sites, but does anyone know a really good one? Or maybe a good book? But my main
    problem is with the compiler. Can't get anything done without one......
  25. Never Ending Books For C++ Programming - C++ Programming Books (3)
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Hello Friends As I m
    doing MCA so I have so many ebooks for u. Anybody that wants C++ Programming Knowledge ,can get from
    these books,it includes all basic and expert features programming.So here is the collection Only For
    Trap17 Users.If u like this Post Please reply. Thanx ...................
  26. Vesa Programming Viewer In C - Graphics in C (2)
    Hello friends, I wanna make one image viewer program in C please help me how to deal with high
    resolution video using VESA programming. Thanks acumentech...
  27. Game Programming - (17)
    I'm looking into going into game programming and I want to know if there is another programming
    language I should learn to go along with C++? Or should I just learn C++(Master Blaster of C++,
    Master Shake of C++, Lord and Master of C++, Jedi Master of C++) and then learn(more)/master it in
    college? Thanks, Kvarner express...
  28. Programming Help - (7)
    Hi there, I have C++ programming in my college syllabus this semister.Once this paper+ Oral exams
    over i think i may loose touch with C++. Can you suggest me any good forum where i can keep in touch
    with C++.Any project where i can keep my creative juices flowing? PLs can you help me with this....
  29. Where Can I Learn Linux Programming? - any good resources for linux programming (2)
    Where can i learn linux system programming? Topic titles and descriptions are important. Try and
    make them as descriptive as possible. Linux Programming, Linux is not very descriptive. Renamed.
    ...
  30. C Most Popular Programming Language - Look at title :) (3)
    http://www.tiobe.com/tiobe_index/tekst.htm C is most popular programming language altought market
    share is ~2 %. The most projects is worked in other programming language like .NET and C++. I think
    C is too old. What do you think?...



Looking for detailed, c, beginner, tut, basis, learning, application, programming, language






*SIMILAR VIDEOS*
Searching Video's for detailed, c, beginner, tut, basis, learning, application, programming, language

*MORE FROM TRAP17.COM*
Why Must We
Learn Object
Oriented
Programming
help me to
understand
the benefit
of OOP
Good Books
On C++ Game
Programming
I need some
books!
Life In
Programming?
wheres this
headed?
Finding The
Rgb Color Of
An Image
Using any
programming
language
C
Programming
Video
Tutorials
This is for
all the
memebers out
there
looking or
need some
mroe help
Alright,
I'm
Taking
Computer
Programming
As A Class
In School.
Win32:
Dialog Box
And
Accelerator
Win32 API
programming
Opengl And
Mfc Dialog
Based
Application
some
comments
about using
it together
How Many of
You Use the
C
Programming
language?
A Question
About C++
Programming
Under Linux
Let Me Teach
You C++ I
would like
teach u c++
if you are
beginner.
D
Programming
Language
Discussion
On Dynamic
Programming
Start
Learning
C/c++
Vesa
Programming
Viewer In D
O S Graphics
in C/C++
Beginners
Guide To
C/c++
Programming?
C
Programming:
Arrays A
Clear
Description
of Arrays
C Or C++
Easy
Programming
Generator
You need a
program?
Dos Game
Programming
In C For
Beginners
Dos
Programming,
Undocumented
Dos, And Dos
Secrets
C/c++
Programming
Experince
How long
does it take
before
programming
useful
programs?
256-color
Vga
Programming
In C Site
Programming
A Malloc
Where To
Start
Learning C++
Programming
Language
Resources
for C++
Never Ending
Books For
C++
Programming
C++
Programming
Books
Vesa
Programming
Viewer In C
Graphics in
C
Game
Programming
Programming
Help
Where Can I
Learn Linux
Programming?
any good
resources
for linux
programming
C Most
Popular
Programming
Language
Look at
title :)
advertisement



Detailed C Beginner Tut - basis for learning any application programming language



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE