Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

Thursday, November 24, 2011

Learn C programming tutorial lesson 10 - Text and data files


Files let you store data on secondary storage such as a hard disk so that your programs can later retrieve that data again. There are 2 types of files which are text files and data files.

Text files

Text files are used for storing character strings in a file. To create a text file you must first declare a file pointer.
#include

int main()
{
   FILE *f;
   return 0;
}

Learn C programming tutorial lesson 9 - Structures


We already know that arrays are many variables of the same type grouped together under the same name. Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create a structure called person which is made up of a string for the name and an integer for the age. Here is how you would create that person structure in C:
struct person
{
   char *name;
   int age;
};

Learn C programming tutorial lesson 8 - Functions


Functions are sub-programs. You have already been using a function which is the main function.
You must always declare a function before the function that calls it. The main function will be calling our function so we will put ours above main.
First put its return value such as int or char. If you don't want a return value then use void. After that give it a unique name and put a set of brackets after that. You then put the set of curly brackets which will have the sub-program between them. We will call our function Hello because it will simply print the word Hello on the screen.
#include

void Hello()
{
   printf("Hello\n");

Learn C programming tutorial lesson 7 - Strings


A string is an array of characters. Strings must have a 0 or null character after the last character to show where the string ends. The null character is not included in the string.
There are 2 ways of using strings. The first is with a character array and the second is with a string pointer.
A character array is declared in the same way as a normal array.
char ca[10];
You must set the value of each individual element of the array to the character you want and you must make the last character a 0. Remember to use %s when printing the string....

Learn C programming tutorial lesson 6 - Arrays

Up until now if you wanted to declare 5 variables you would have to do something like this:
int i1,i2,i3,i4,i5;
What if you wanted to declare 100 variables? That would take quite a long time. If you use an array on the other hand then you can declare as many variables as you want with only 1 variable name.
An array is declared in the same way as a normal variable except that you must put square brackets after the variable name. You must also put the amount of elements you want in the array in these sqaure brackets.
int a[5]; 
...

Learn C programming tutorial lesson 5 - Pointers

What are pointers

A pointer is a variable that holds a memory address. Because it holds a memory address it is said to be pointing to the value at that memory location. You can use a pointer in a certain way to get the value at the address to which it points.
Pointers can be either typed or untyped. A typed pointer points to a particular variable type such as an integer. An untyped pointer points to any data type....

Learn C programming tutorial lesson 4 - Loops


What are loops

Sometimes you will want to do something a lot of times. An example would be printing a character at the beginning of each line on the screen. To do this you would have to type out 24 printf commands because there are 25 rows on the screen and the 25th row will be left blank. We can use a loop to do this for us and only have to type 1 printf command. There are 3 basic types of loops which are the for loop, while loop and do while loop.

Learn C programming tutorial lesson 3 - Decisions

The if statement So far we have only learnt how to make programs that do one thing after the other without being able to make decisions. The if statement can be used to test conditions so that we can alter the flow of a program. The following example has the basic structure of an if statement:
#include<stdio.h>

int main()
{
   int mark;
   char pass;
   scanf("%d",&mark);
   if (mark > 40)
      pass = 'y';
   return 0;


Learn C programming tutorial lesson 2 - Variables and constants


What are variables

Variables in C are memory locations that are given names and can be assigned values. We use variables to store data in memory for later use. There are 2 basic kinds of variables in C which are numeric and character.

Numeric variables

Numeric variables can either be integer values or they can be Real values. Integer values are whole numbers without a fraction part or decimal point in them. Real numbers can have a decimal point in them.

Learn C programming tutorial lesson 1 - Hello World

 

What is C and why learn it

C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories. C was originally designed for writing system software but today a variety of software programs are written in C. C can be used on many different types of computers but is mostly used with the UNIX operating system.
It is a good idea to learn C because it has been around for a long time which means there is a lot of information available on it. Quite a few other programming languages such as C++ and Java are also based on C which means...

Setec Institute || Group : SH6 | | Name : Kim Chanthy. Powered by Blogger.
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Hot Sonakshi Sinha, Car Price in India