Computersight > Programming

Lets Learn C : Printing Strings on to the Screen

An introductory article for who thinks to start learning C.

Here is the first article of my tutorial set. I aim to teach you the basics of C. In this first lesson, I am going to teach you how to output a series of strings on to terminal screen of C program.

Virtually every program code has inputs and outputs. Before compiling a source code, programs generally request an input from the user and then output it to the screen after compiling if the program is well designed and there is no error inside it. Usually, as the program becomes more complicated, error possibility increases. A good software expert easily realizes where the code has faults and corrects it. Since our first code will be very small and very simple, we will not face with any error.

Before starting to write code, we initially have a compiler which is going to evaluate our code. I use Dev C for this. There are many other compilers which run on different platforms like Unix, Linux and Windows.

In this project, we will output the names of the subprograms of Triond on to C terminal screen. This is the simplest algorithm since there is no input in this example. Let's start writing our code step by step.

Step 1: Open the File from the menu bar of C software and save as the blank page Project1. This yields a file with an extension of cpp.

Step 2: Describe the name and aim of the programs. To do so, we use comments. Comments are ignored by the compiler. For commenting, we use some special scripts like double slash or slash-asterisk character .

If we use a single line comment, double slash is enough. However, if our comment is placed more than one line, we use double slash for each line or take the commented part between slash-asterisk and asterisk-slash characters .

Step 3: C needs library files which define what the input and output functions are and what they do when they are used in a code. Iostream is the library file of input and output function.

Before the name of library files, we use a special character, preprocessor directive character. Include is used before the name of every library file and such file names are placed mathematical comparison characters.

Step 4: Every C code uses functions. The default function is main. Main function is the first function compiled by the programs. This function usually calls other functions. Before the name of function, we specify which type of output our code returns. In our program, we think that it returns to integer and use int. After the function name, we use parantheses. In this example, there will be nothing between parantheses but in more complicated programs, there may be parameter names and it's types or definitions. We place our statements between left brace and right brace.

Step 5: To print on to the screen,we use cout function. We simply place our string inside double quote characters. Every statement inside the functions ends with a special semicolon character.

Step 6: To check the validity, we use return function.In this simple example, it returns to 0.

Click here for the code

4
Liked It
I Like It!
Related Articles
Let's Learn C++: Printing Strings on to the Screen  |  Lets Learn C++: Printing Strings on to the Screen
More Articles by Rodallega
Solidworks Tutorial: How to Draw Circle and Filleted Arc  |  Solidworks Tutorial: How to Draw Simple 2D Geometries
Latest Articles in Programming
Microsoft Sql Server 2005: An Easy Task  |  SQL and Databases
Comments (6)
#1 by Picos, Aug 24, 2008
C++ is a very useful language, because it gives the programmer a lot of control, but also is abstract enough so development can be done fairly quickly. C++ is a very portable language as well, because it is a third-generation language, and because it has a well defined set of standards written for it.
#2 by Dodgers, Aug 24, 2008
C++ fully supports object-oriented programming, including the four pillars of object-oriented development: encapsulation, data hiding, inheritance, and polymorphism. Encapsulation and Data Hiding When an engineer needs to add a resistor to the device she is creating, she doesn't typically build a new one from scratch. She walks over to a bin of resistors, examines the colored bands that indicate the properties, and picks the one she needs. The resistor is a "black box" as far as the engineer is concerned--she doesn't much care how it does its work as long as it conforms to her specifications; she doesn't need to look inside the box to use it in her design.
#3 by Patchman, Aug 24, 2008
While it is true that C++ is a superset of C, and that virtually any legal C program is a legal C++ program, the leap from C to C++ is very significant. C++ benefited from its relationship to C for many years, as C programmers could ease into their use of C++. To really get the full benefit of C++, however, many programmers found they had to unlearn much of what they knew and learn a whole new way of conceptualizing and solving programming problems.
#4 by booklover, Aug 24, 2008
C++, perhaps more than other languages, demands that the programmer design the program before writing it. Trivial problems, such as the ones discussed in the first few chapters of this book, don't require much design. Complex problems, however, such as the ones professional programmers are challenged with every day, do require design, and the more thorough the design, the more likely it is that the program will solve the problems it is designed to solve, on time and on budget. A good design also makes for a program that is relatively bug-free and easy to maintain. It has been estimated that fully 90 percent of the cost of software is the combined cost of debugging and maintenance. To the extent that good design can reduce those costs, it can have a significant impact on the bottom-line cost of the project.
#5 by razorsharpwit, Aug 24, 2008
Compile-time errors can occur for any number of reasons. Usually they are a result of a typo or other inadvertent minor error. Good compilers will not only tell you what you did wrong, they'll point you to the exact place in your code where you made the mistake. The great ones will even suggest a remedy!
#6 by bully, Aug 29, 2008
Programming skills are useful for anyone who has to think critically to solve problems. In order to program a solution to a problem, you have to think of it in terms of the simplest possible steps, and then implement them. Since the program does exactly what you tell it to (as opposed to what you wanted it to do), you are forced to pay more attention to the little finicky details than you normally would, which makes you a better problem solver in turn.
Post Your Comment:
Name:  
Copy the code into this box:  
Post comment with your Triond credentials?
Inside Computersight

Communication & Networks

 /

Computers

 /

Hardware

 /

Operating Systems

 /

Programming

 /

Software


Popular Tags
Popular Writers
Powered by
Computersight
About Us
Terms of Use
Privacy Policy
Services
Submit an Article
Advertise with Us
Contact

© 2007 Copyright Stanza Ltd. All Rights Reserved.