Showing posts with label Internet. Show all posts
Showing posts with label Internet. Show all posts

Thursday, July 14, 2011

Array And Strings :STRING (CHARACTER ARRAY)

STRING (CHARACTER ARRAY)

Character Arrays [String]

Strings are stored in C as character arrays terminated by the null character, '\0'.
Declaration of string if done as follows
char str[25];
char str1[30] = "MY STUDYROOM";
M
Y

S
T
U
D
Y
R
O
O
M
\0
............

0
1
2
3
4
5
6
7
8
9
10
11
12
............
29
Assigning a character literal to an array is done as follows.
char str1[] = "MY STUDYROOM";
char str2[] = "Nepal"
The compiler automatically sizes the arrays correctly. For this example, str1 is of length 16, str2 is of length 5.
Example 1: Program to find out the length of string
#include<stdio.h>
#include<conio.h>
main()
{
int len;
char str[25];

printf("Enter any string");
scanf("%s", str);

/*loop has semicolon(;) at the end coz loop doesn't contain any statement below it*/
for(len=0; str[len]!='\0' ; len++);

printf("length of string is %d", len);

getch();
}
Example: Write a program to reverse the string
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    int i, j, len;
    char str[25], rstr[25];
   
    printf("Enter any string");
    scanf("%s", str);
 
    //finding out the length of string
    len = strlen(str);
 
//reversing the string
for(i=0, j=len-1; j>=0; j--, i++)
          rstr[i] = rstr[j];
 
printf("Reverse sting is %s", rstr);
 
getch();
}
Example : Write a program to find out no. of vowel, consonant, digit, white space and other character in a sentence provided by an user.
#include<stdio.h>
#include<conio.h>
main()
{
    int i, v=0, c=0, d=0, ws=0, oth=0;
    char str[25];
   
    printf("Enter any string");
    scanf("%s", str);
 
    for(i=0; str[i]!='\0' ; i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
                v = v + 1;
else
                if(str[i]>='a' && str[i]<='z')
                      c = c + 1;
                else
                      if(str[i]>='0' && str[i]<='9')
                            d = d + 1;
                      else
                            if(str[i]==' ' )
                                  ws = ws + 1;
                            else
                                  oth = oth + 1;
}
  printf(" No. of vowel=%d, Consent=%d, Digit=%d, White space=%d and Other=%d", v, c, d, ws, oth);
  getch();
}

Library Functions for String Manipulation

To use any of these functions in your code, the header file "strings.h" must be included.
strlen():
strlen finds the length of string.
Syntax:
int strlen(char* )
Example:
char str[]="MY STYDYROOM";
int len;
len=strlen(str);
output:
len=12

strcpy():
strcpy copies a string, including the null character terminator from the source string to the destination.
Syntax:
Char* strcpy(char* source_string, char* destination_string)
Example:
char dst[25], src[]="MY STYDYROOM";
strcpy(dst, src);
output:
dst = "MY STYDYROOM"
strcat():
This function appends a source string to the end of a destination string.
Example:
char dst[25]="MY ";
char src[ ] = "STUDYROOM";
strcat(dst, src);
Output:
dst = "MY STYDYROOM"
strcmp
This function compares two strings.
  • If the first string is greater than the second, it returns a number greater than zero.
  • If the second string is greater, it returns a number less than zero.
  • If the strings are equal, it returns 0.
int x;
char str1[25], str2[25];
x = strcmp(str1, str2);
o   x > 0 - if the str1 is greater than str2. [i.e. str1="nepal" and str2="japan" ]
o   x< 0  - if the str1 is less than str2. [i.e. str1="japan" and str2="nepal"]
o   x==0 - if str1 is equal to str2. [i.e. str1="nepal" and str2="nepal" ]

Example: Write a program to find out the string is palindrome or nor.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    char str[25], str1[25];
   
    printf("Enter any string");
    scanf("%s", str);
   
    str1 = strrev(str);
 
    if(str==str1)
          printf("Entered string is PALAINDROME");
    else
          printf("Entered string is NOT PALAINDROME");
   getch();
}

Do You Need To Know C Before Learning C++?

Do You Need To Know C Before Learning C++?

Although this question is still a source of debate, and many including the author of this article learned C first, I believe the answer is no. The features of C are supported by C++. After learning C++ you will be able to read and understand most of what you would see in any C program you might encounter and can fill in any missing details easily. Additionally, the techniques used to solve programming problems in an object-oriented language such as C++ differ from a procedural language such as C. C programmers who need to study C++ must unlearn some of their programming techniques and replace them with techniques for object-oriented design.

PROGRAMMING CONCEPT

PROGRAMMING CONCEPT

The earliest computers

It is an astonishing fact that as we enter the 21st century, computers has been around for less than 60 years. Many of those who worked on the earliest computer are still alive to tell us of their experiences. If you ever get a chance to visit Bletchley Park, don't miss it - it is the location of the breaking of the Enigma code (used by the Germans to code all their most secret messages), with the aid of the first programmable computer, named Colossus, built for this purpose in 1943. A fascinating exhibition the fie story and Colossus has been reconstructed there.

Generations of programming language

Machine language - the first generation

Programming languages are often characterised by 'generation'- The first generation of computer language, known as machine code, executes directly without translation. Machine code is the actual pattern of 0s and 1s used in a computer's memory. The programming of Colossus and other early computers was laboriously done with toggle switches representing a pattern of binary codes for each instruction.
Machine language, however it is entered into a computer, is time-consuming, laborious and error-prone. Few programmers code in it today. A language suited to fie particular application would be used instead.

Assembly code - the second generation

In the 1950s when computers were first used commercially, machine code gave way to assembly code, which allowed programmers to use mnemonics (abbreviations that represent the instructions in a more memorable way) and denary numbers (i-e.0-9) instead of 0s and 1s. Thus ADD or ADX might be an instruction to add two numbers, SIJB or SBX an instruction to subtract.
Programs written in assembly languages have to be translated into machine code before they can be executed, using a program called an assembler-There is more or less a one-to-one correspondence between each assembly code statement and its equivalent machine code statement, which means that programs can be written in the most efficient way possible, occupying as little space as possible and executing as fast as possible. For this reason assembly code is still used for applications where timing or storage space is critical. Assembly languages are called low level languages because they are close to machine code and the detail of the computer architecture.
Since different types of computer have different instruction sets, which depend on how the machine carries out the instructions, both machine code and assembly code are machine-dependent - each type of computer will have its own assembly language.

lmperative high level languages - the third generation

As computer use increased dramatically in the 1950s, the need grew to make it easier and faster to write error-free programs. Computer manufacturers and user groups started to develop so-called high-level languages such as Algol (standing for AlGOrithmic Language) and Fortran (standing for FORmula TRANslation).In the 1950s most of the people actually writing programs were scientists, mathematicians and engineers and so both these languages were created to be used in mathematical applications.
COBOL (Common Business Oriented Language) was invented by the redoubtable Admiral Grace Hopper in 1960 specifically for writing commercial and business, rather than scientific, programs.-Whilst serving in the US Navy in 1947, Grace Hopper was investigating why one of the earliest computers was not working, and discovered a small dead moth in the machine. After removing it (and taping it in her logbook) the machine worked fine, and from then on computer errors were known as 'bugs'.
Other third generation languages followed: BASIC was created in the 1960s as a language for students to learn programming. Early versions of the language however did not contain the facilities to write well-structured programs that were easy to maintain and debug, although the language has since developed. In I97l Nicklaus Wirth designed Pascal (named after the seventeenth century French mathematician) to teach structured programming to students.
High level languages are so-called because they are independent of the architecture of any particular computer; one statement written in a high level language is translated into several machine code instructions before it can be executed. The term imperative high level language refers to languages such as Pascal, BASIC, COBOL and FORTRAN - in contrast to object-oriented and declarative languages, which you will learn about in the second year of this course.

Fourth-Generation programming language

A fourth-generation programming language (4GL) is a programming language closer to human languages than typical high-level programming languages. Such languages arose after the introduction of modern, block-structured third-generation programming languages, which improved the process of software development. Most 4GLs are used to access databases. For example, a typical 4GL command is
SQL > SELECT * FROM tblStudent WHERE gender='Male'
Why use assembly code?
Assembly language, although it is laborious to write and hard to debug, is still used in some circumstances, for example:
  • when there is a need for the program to execute as fast as possible;
  • when the program must occupy as little space as possible;
Parts of an operating system, and device drivers that control the operation of devices such as a printer, mouse or CD-ROM may be written in assembly code. Programs in embedded systems like satellite decoders, encryption and decryption software, and routines that are called frequently from high-level programs may also be written in assembly code.

Types of program translator

There are three types of program used for translating the code that a programmer writes into a form (i.e. machine code) that the computer can execute. These are:
  • assembler
  • compiler
  • interpreter.

Assembler

An assembler is a program that translates an assembly code program into machine code ready for the computer to execute it. Since each type of computer has its own assembly language, it also has its own assembler. The assembler itself could be written in assembly code or in a high level language such as C, which has special facilities useful for this type of programming.

Compiler

A compiler is a program that translates a high level language program into machine code. The Turbo Pascal compiler, for example, translates a program written in Turbo Pascal on a PC into object code, which can be run on a PC. The code written by the programmer is known as the source code, and the compiled code is known as the object code.
A compiler is a complex program which takes the source code and scans through it several times, each time performing different checks and building up tables of information needed to produce the fina1 object code. When you write a short program, this process appears to happen almost instantaneously, but a long program of several thousand lines can take several minutes to compile.
Compiler: Translates the whole high level language source code into object code, which can then be executed without the presence of a compiler.

Interpreter

An interpreter also translates high-level source code. However the crucial difference between a compiler and an interpreter is that an interpreter translates one line at a time and then executes it; no object code is produced, and so the program has to be interpreted each time it is to be run. If the program performs a section of code 10,000 times, then that section of code is translated into machine code 10,000 times as each line is interpreted and then executed.
Interpreter: Analyses the source code statement by statement as execution proceeds decoding each statement and calling routines to carry out each instruction.

Relative advantages of compilers and interpreters

A compiler has many advantages over an interpreter:
  • the object code can be saved on disk and run whenever required without the need to recompile. However, if an error is discovered in the program, the whole program has to be recompiled.
  • the object code executes faster than interpreted code.
  • the object code produced by a compiler can be distributed or executed without having to have the compiler present.
  • the object code is more secure, as it cannot be read without a great deal of 'reverse engineering'.

An interpreter has some advantages over a compiler:

  • it is useful for program development as there is no need for lengthy recompilation each time an error is discovered.
  • it is easier to partially test and debug programs.
Typically, a programmer might use an interpreter during program development. A program that is tested and ready for distribution would then be compiled and the saved object code would be distributed.

Wednesday, July 13, 2011

NETWORK PROTOCOL:

NETWORK PROTOCOL:

Internet Protocol Suite
Protocols are the sets of rules by which communication over a network is achieved. Protocols are responsible for enabling and controlling network communication: They set the rules for the representation of data, the signals used in communications (e.g., signals regarding how the connection will be established or how information is exchanged), the detection of errors, and the authentication of computing devices on the network.
In order for different computers to communicate with each other they must both speak the same language. The rules for these languages are called Network Protocols. A protocol describes how a packet of information is organized and the rules it follows when traveling across the network.

Types of Protocol

1. TCP/IP (Transmission Control Protocol/Internet Protocol)

TCP/IP is the basic communication language or protocol of the Internet. It can also be used as a communications protocol in a private network (either an intranet or an extranet). When you are set up with direct access to the Internet, your computer is provided with a copy of the TCP/IP program just as every other computer that you may send messages to or get information from also has a copy of TCP/IP.
TCP/IP is a two-layer program. The higher layer, TCP, manages the assembling of a message or file into smaller packets that are transmitted over the Internet and received by a TCP layer that reassembles the packets into the original message. The lower layer, IP, handles the address part of each packet so that it gets to the right destination. Each gateway computer on the network checks this address to see where to forward the message. Even though some packets from the same message are routed differently than others, they'll be reassembled at the destination.
TCP/IP uses the client/server model of communication in which a computer user (a client) requests and is provided a service (such as sending a Web page) by another computer (a server) in the network. TCP/IP communication is primarily point-to-point, meaning each communication is from one point (or host computer) in the network to another point or host computer.

2. HTTP(Hypertext Transfer Protocol)

HTTP is the set of rules for transferring files (text, graphic images, sound, video, and other multimedia files) on the World Wide Web. As soon as a Web user opens their Web browser, the user is indirectly making use of HTTP. HTTP is an application protocol that runs on top of the TCP/IP suite of protocols (the foundation protocols for the Internet).
HTTP concepts include the idea that files can contain references to other files whose selection will extract additional transfer requests. HTTP daemon, a program that is designed to wait for HTTP requests and handle them when they arrive. Your Web browser is an HTTP client, sending requests to server machines. When the browser user enters file requests by either "opening" a Web file (typing in a Uniform Resource Locator or URL) or clicking on a hypertext link, the browser builds an HTTP request and sends it to the Internet Protocol address (IP address) indicated by the URL. The HTTP daemon in the destination server machine receives the request and sends back the requested file or files associated with the request.

3. FTP(File Transfer Protocol)

A FTP better known as File Transfer Protocol basically is applied to transfer data from one particular computer to another above a world-wide network.
Usually, FTP is a primarily applied protocol for exchanging data over a particular network which normally supports TCP/IP protocol. Generally there are two types of computer occupied in an FTP data transfer they are the server and the client. The FTP server, administrating server software, depends on the network for network connection request from supplementary computers. The consumer computer, which is administrating the FTP client software, starts a connection to the server. As soon as the connection is started, the client can perform numerous file manipulations like uploading them, downloading them, giving them new names, etc. Generally any software company or programming individual can create an FTP server because the protocol is open standard.

4. SMTP (Simple Mail Transfer Protocol)

SMTP is a delivery protocol only. It cannot pull messages from a remote server on demand. Other protocols, such as the Post Office Protocol (POP) and the Internet Message Access Protocol (IMAP) are specifically designed for retrieving messages and managing mail boxes. However, SMTP has a feature to initiate mail queue processing on a remote server so that the requesting system may receive any messages destined for it. POP and IMAP are preferred protocols when a user's personal computer is only intermittently powered up, or Internet connectivity is only transient and hosts cannot receive message during off-line periods.

5. TELNET

Telnet is a user command and an underlying TCP/IP protocol for accessing remote computers. Through Telnet, an administrator or another user can access someone else's computer remotely. On the Web, HTTP and FTP protocols allow you to request specific files from remote computers, but not to actually be logged on as a user of that computer. With Telnet, you log on as a regular user with whatever privileges you may have been granted to the specific application and data on that computer.
The result of this request would be an invitation to log on with a userid and a prompt for a password. If accepted, you would be logged on like any user who used this computer every day.Telnet is most likely to be used by program developers and anyone who has a need to use specific applications or data located at a particular host computer.

E-MAIL

E-MAIL

E-mail (electronic mail) is the exchange of computer-stored messages by telecommunication. E-mail messages are usually encoded in ASCII text. However, you can also send non-text files, such as graphic images and sound files, as attachments sent in binary streams. E-mail was one of the first uses of the Internet and is still the most popular use. A large percentage of the total traffic over the Internet is e-mail. E-mail can also be exchanged between online service provider users and in networks other than the Internet, both public and private.
E-mail can be distributed to lists of people as well as to individuals. A shared distribution list can be managed by using an e-mail reflector. Some mailing lists allow you to subscribe by sending a request to the mailing list administrator. A mailing list that is administered automatically is called a list server.
E-mail is one of the protocols included with the Transport Control Protocol/Internet Protocol (TCP/IP) suite of protocols. A popular protocol for sending e-mail is Simple Mail Transfer Protocol and a popular protocol for receiving it is POP3. Both Netscape and Microsoft include an e-mail utility with their Web browsers.

Advantages of Email

The benefits of e-mail are huge in number.
  • Easy to use: E-mail frees us from the tedious task of managing data of daily use. It helps us to manage our contacts, send mails quickly, maintain our mail history, store the required information, etc.
  • Speed: The e-mail is delivered instantly, anywhere across the globe. No other service matches the e-mail in terms of speed.
  • Easy to prioritize: Since the mails have subject lines, it is easy to prioritize them and ignore unwanted mails.
  • Reliable and secure: Constant efforts are being taken to improve the security in electronic mails. Thus making it one of the secured ways of communication.
  • Informal and conversational: The language used in e-mails is generally simple and thus makes the communication informal. Sending and receiving e-mails takes less time, so it can be used as a tool for interaction.
  • Easier for reference: When one needs to reply to a mail, there is a provision in the mailing system to attach the previous mails as references. This refreshes the recipient's knowledge, on what he is reading.
  • Automated e-mails: It is possible to send automated e-mails using special programs like the autoresponders. The autoresponders reply back to the sender with generalized pre-written text messages.
  • Environment friendly: Postal mails use paper as a medium to send letters. Electronic mail thus, saves a lot of trees from being axed. It also saves fuel needed in transportation.
  • Use of graphics: Colorful greeting cards and interesting pictures can be sent through e-mails. This adds value to the e-mail service.
  • Advertising tool: Many individuals and companies are using e-mails to advertise their products, services, etc.

Disadvantages of Email

The e-mails, though beneficial in our day-to-day life, has got its own drawbacks that are off late coming to the fore.

  • Viruses: These are computer programs having the potential to harm a computer system. These programs copy themselves and further infect the computer. The recipient needs to scan the mails, as viruses are transmitted through them and have the potential to harm computer systems.
  • Spam: E-mails when used to send unsolicited messages and unwanted advertisements create nuisance and is termed as Spam. Checking and deleting these unwanted mails can unnecessarily consume a lot of time, and it has become necessary to block or filter the unwanted e-mails by means of spam filters. Spamming includes, sending hoax e-mails. E-mail spoofing is another common practice, used for spamming. Spoofing involves deceiving the recipient by altering the e-mail headers or the addresses from which the mail is sent.
  • Hacking: The act of breaking into computer security is termed as hacking. After the e-mail is sent and before it is received by the desired recipient, it "bounces" between servers located in different parts of the world. Hence, the e-mail can be hacked by a professional hacker.
  • Misinterpretation: One has to be careful while posting any kind of content through an e-mail. If typed in a hurry, the matter could be misinterpreted.
  • Lengthy mails: If the mail is too long and not properly presented the reader may lose interest in reading it.
  • Not suitable for business: Since the content posted via e-mails is considered informal, there is a chance of business documents going unnoticed. Thus, urgent transactions and especially those requiring signatures are not managed through e-mails.
  • Crowded inbox: Over a period of time, the e-mail inbox may get crowded with mails. It becomes difficult for the user to manage such a huge chunk of mails.

SEARCH ENGINES

SEARCH ENGINES
A web search engine is designed to search for information on the World Wide Web and FTP servers. The search results are generally presented in a list of results and are often called hits. The information may consist of web pages, images, information and other types of files. Some search engines also mine data available in databases or open directories. Unlike web directories, which are maintained by human editors, search engines operate algorithmically or are a mixture of algorithmic and human input.

List of Search Engines

1. Google (http://www.google.com)

Voted four times Most Outstanding Search Engine by Search Engine Watch readers, Google has a well-deserved reputation as the top choice for those searching the web. The crawler-based service provides both comprehensive coverage of the web along with great relevancy. It's highly recommended as a first stop in your hunt for whatever you are looking for.

2. Yahoo (http://www.yahoo.com)

Launched in 1994, Yahoo is the web's oldest "directory," a place where human editors organize web sites into categories. However, in October 2002, Yahoo made a giant shift to crawler-based listings for its main results. These came from Google until February 2004. Now, Yahoo uses its own search technology

3. Ask (http://www.ask.com)

Ask Jeeves initially gained fame in 1998 and 1999 as being the "natural language" search engine that let you search by asking questions and responded with what seemed to be the right answer to everything.

4. AltaVista (http://www.altavista.com)

AltaVista opened in December 1995 and for several years was the "Google" of its day, in terms of providing relevant results and having a loyal group of users that loved the service. Sadly, an attempt to turn AltaVista into a portal site in 1998 saw the company lose track of the importance of search. Today, AltaVista is once again focused on search. Results come from Yahoo, and tabs above the search box let you go beyond web search to find images, MP3/Audio, Video, human category listings and news results.

5. Live Search (http://www.live.com/)

Live Search (formerly Windows Live Search) is the name of Microsoft's web search engine, successor to MSN Search, designed to compete with the industry leaders Google and Yahoo. The search engine offers some innovative features, such as the ability to view additional search results on the same web page (instead of needing to click through to subsequent search result pages) and the ability to adjust the amount of information displayed for each search-result (i.e. just the title, a short summary, or a longer summary). It also allows the user to save searches and see them updated automatically on Live.com. Now a days this name is changed int BING.COM