HTML Attributes

HTML elements can have attributes

  1. Attributes provide additional information about an element
  2. Attributes are always specified in the start tag
  3. Attributes come in name/value pairs like: name=”value”

The lang Attribute

The document language can be declared in the <html> tag.

The language is declared in the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines:

<html lang=”en-US”>

The first two letters specify the language (en). If there is a dialect, use two more letters (US).

The title Attribute

HTML paragraphs are defined with the <p> tag.

<p title=”wordpress”>

<P> WordPress is a free and open-source content management system (CMS) based on PHP and MySQL. WordPress is installed on a web server, which either is part of an Internet hosting service or is a network host itself; the first case may be on a service like WordPress.com.</P>

All HTML Attributes

 

Attribute Description
alt Specifies an alternative text for an image, when the image cannot be displayed
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element
title Specifies extra information about an element (displayed as a tool tip)

 

Empty HTML Elements

Tags

HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Empty elements can be “closed” in the opening tag like this: <br />.

HTML5 does not require empty elements to be closed. But if you want stricter validation, or you need to make your document readable by XML parsers, you should close all HTML elements.

HTML 5 Demo 1

Tags

HTML 5 Demo 1

<!DOCTYPE html> <!– The DOCTYPE declaration defines the document type to be HTML–>
<html> <!– describes an HTML document–>
<head><!– provides information about the document –>
<title>Demo 1 By Prasad Sawant</title><!– provides a title for the document –>
</head>
<body><!– describes the visible page content –>
<h1>Demo 1</h1><!– H1 to H5 are describes a heading, NB no need to give break after heading –>
<h2>Demo 1</h2>
<h3>Demo 1</h3>
<h4>Demo 1</h4>
<h5>Demo 1</h5>

<p>The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and display them.The browser does not display the HTML tags, but uses them to determine how to display the document:</p> <!– describes a paragraph–>

</body>
</html>

 

What is Linux Shell ?

Computer understand the language of 0’s and 1’s called binary language.

In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in Os there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is pass to kernel.

Shell is a user program or it’s environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.

Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.

Several shell available with Linux including:

Shell Name
Developed by
Where
Remark
BASH ( Bourne-Again SHell ) Brian Fox and Chet Ramey Free Software Foundation Most common shell in Linux. It’s Freeware shell.
CSH (C SHell) Bill Joy University of California (For BSD) The C shell’s syntax and usage are very similar to
the C programming language.
KSH (Korn SHell) David Korn AT & T Bell Labs
TCSH See the man page.
Type $ man tcsh
TCSH is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).

Tip: To find all available shells in your system type following command:
$ cat /etc/shells

Note that each shell does the same job, but each understand a different command syntax and provides different built-in functions.

In MS-DOS, Shell name is COMMAND.COM which is also used for same purpose, but it’s not as powerful as our Linux Shells are!

Any of the above shell reads command from user (via Keyboard or Mouse) and tells Linux Os what users want. If we are giving commands from keyboard it is called command line interface ( Usually in-front of $ prompt, This prompt is depend upon your shell and Environment that you set or by your System Administrator, therefore you may get different prompt ).

Tip: To find your current shell type following command
$ echo $SHELL

Linked List vs Array

Both Arrays and Linked List can be used to store linear data of similar types, but they both have some advantages and disadvantages over each other.

Following are the points in favour of Linked Lists.

(1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage, and in practical uses, upper limit is rarely reached.

(2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.

For example, suppose we maintain a sorted list of IDs in an array id[].

id[] = [1000, 1010, 1050, 2000, 2040, …..].

And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).

Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved.

So Linked list provides following two advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion

Linked lists have following drawbacks:
1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the list.
3) Arrays have better cache locality that can make a pretty big difference in performance.

C Programming Dynamic Memory Allocation

Tags

C Programming Dynamic Memory Allocation

The exact size of array is unknown untill the compile time,i.e., time when a compier compiles code written in a programming language into a executable form. The size of array you have declared initially can be sometimes insufficient and sometimes more than required. Dynamic memory allocation allows a program to obtain more memory space, while running or to release space when no space is required.
Although, C language inherently does not has any technique to allocated memory dynamically, there are 4 library functions under “stdlib.h” for dynamic memory allocation.

Function Use of Function
malloc() Allocates requested size of bytes and returns a pointer first byte of allocated space
calloc() Allocates space for an array elements, initializes to zero and then returns a pointer to memory
free() dellocate the previously allocated space
realloc() Change the size of previously allocated space

malloc()
The name malloc stands for “memory allocation”. The function malloc() reserves a block of memory of specified size and return a pointer of type void which can be casted into pointer of any form.
Syntax of malloc()
ptr=(cast-type*)malloc(byte-size)
Here, ptr is pointer of cast-type. The malloc() function returns a pointer to an area of memory with size of byte size. If the space is insufficient, allocation fails and returns NULL pointer.
ptr=(int*)malloc(100*sizeof(int));
This statement will allocate either 200 or 400 according to size of int 2 or 4 bytes respectively and the pointer points to the address of first byte of memory.
// sum of n elements using malloc
// author : Prof.Prasad Sawant
#include
#include
#include
void main()
{
int n,i,*ptr,sum=0;
clrscr();
printf(“How many number of elements do u want ?”);
scanf(“%d”,&n);
ptr=(int *)malloc(n* sizeof(int));
if(ptr==NULL)
{
printf(“Error !!!!!!”);
exit(0);

}
printf(“\n Enter elements in array”);
for(i=0;i<n;i++)
{
scanf("%d",ptr+i);
sum+=*(ptr+i);
}
printf("Sum is %d ",sum);
free(ptr);

getch();
}

calloc()
The name calloc stands for "contiguous allocation". The only difference between malloc() and calloc() is that, malloc() allocates single block of memory whereas calloc() allocates multiple blocks of memory each of same size and sets all bytes to zero.
// sum of n elements using malloc
// author : Prof.Prasad Sawant

#include
#include
#include
void main()
{
int n,i,*ptr,sum=0;
clrscr();
printf(“How many number of elements do u want ?”);
scanf(“%d”,&n);
ptr=(int *)calloc(n,sizeof(int));
if(ptr==NULL)
{
printf(“Error !!!!!!”);
exit(0);

}
printf(“\n Enter elements in array”);
for(i=0;i<n;i++)
{
scanf("%d",ptr+i);
sum+=*(ptr+i);
}
printf("Sum is %d ",sum);
free(ptr);

getch();
}

free()
Dynamically allocated memory with either calloc() or malloc() does not get return on its own. The programmer must use free() explicitly to release space.
syntax of free()
free(ptr);
realloc()
If the previously allocated memory is insufficient or more than sufficient. Then, you can change memory size previously allocated using realloc().
Syntax of realloc()
#include
#include
int main(){
int *ptr,i,n1,n2;
printf(“Enter size of array: “);
scanf(“%d”,&n1);
ptr=(int*)malloc(n1*sizeof(int));
printf(“Address of previously allocated memory: “);
for(i=0;i<n1;++i)
printf("%u\t",ptr+i);
printf("\nEnter new size of array: ");
scanf("%d",&n2);
ptr=realloc(ptr,n2);
for(i=0;i<n2;++i)
printf("%u\t",ptr+i);
return 0;
}

Write a ‘C’ Program to find the union and intersection of the two sets of integer (Store it in two arrays)

#include
#include
void main()
{
int i,k=0,x[10],y[10],c[25],j,n,n1,d[25],f=0;
clrscr();
printf(“\n how many elements in SET 1:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("\n please enter the elements no %d",i+1);
scanf("%d",&x[i]);
}
printf("\n how many elements in set 2:");
scanf("%d",&n1);
for(i=0;i<n1;i++)
{
printf("\n please enter elements no %d",i+1);
scanf("%d",&y[i]);
}
for(i=0;i<n;i++)
{
c[k]=x[i];
k++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n1;j++)
{
if(y[i]==x[j])
break;
}
if(j==n)
{
c[k]=y[i];
k++;
}
}
printf("\n the union set is:{");
for(i=0;i<k;i++)
printf("%d",c[i]);
printf("}\n");
for(j=0;j<n;j++)
{
for(i=0;i<n1;i++)
{
if(y[i]==x[j])
break;
}
if(i!=n1)
{
d[f]=y[i];
f++;
}
}
printf("\n the intersection set is :{");
for(i=0;i<f;i++)
printf("%d",d[i]);
printf("}");
getch();
}

c program to count the number of character ,number of lines from a text file and display the result

#include
#include
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf(“\n enter the source file name”);
gets(fname);
fr=fopen(fname,”r”);
if(fr==NULL)
{
printf(“\n error \n”);
exit(0);
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc++;
if(ch==’ ‘);
now++;
if(ch==’\n’)
{
nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
printf(“\n total no of character=%d”,noc);
printf(“\n total no of words=%d”,now);
printf(“\n total no of lines=%d”,nol);
getch();
}

‘C’ Program to accept a string from user and display the alternate characters

#include
#include
void main()
{
int flag=0;
char fname[30],ch;
FILE *fp;
clrscr();
printf(“\n enter the file name”);
gets(fname);
fp=fopen(fname,”r”);
if(fp==NULL)
{
printf(“\n file can not be open”);
exit(0);
}
ch=fgetc(fp);
while(ch!=EOF)
{
if(flag==0)
{
printf(“%c”,ch);
flag=1;
}
else
flag=0;
ch=fgetc(fp);
}
fclose(fp);
getch();
}