Monday, August 27, 2007

validate rss and atom

validate rss and atom
================


http://feedvalidator.org/

http://rss.scripting.com/

http://www.walidator.com/

http://www.ldodds.com/rss_validator/

http://feeds.archive.org/validator

http://www.ldodds.com/rss_validator/1.0/validator.html

http://aggregator.userland.com/validator

http://www.w3.org/RDF/Validator/ (RDF validator)

Web Syndication with RSS and ATOM

Web Syndication with RSS and ATOM
===========================



Syndication lets sites share information across the Web, making it easy to do things like display headlines from a site or collection of sites. Most of the syndicated feeds are written in RSS, a simple XML vocabulary (in several varieties) for summarizing information about a site. Several popular flavors of RSS are leading the pack, with upstart Atom growing in acceptance

Eg: news feeds you might find in news site, blogs etc.

There are accepted standards for syndication:


1) RSS

* RSS 0.91 (Rich Site Summary) and RSS 0.92
* RSS 1.0 (RDF Site Summary)
* RSS 2.0 (Really Simple Syndication)


2) ATOM


Formats:

For RSS 0.91
============


<rss version="0.91">

<channel>

<title>Computer Bapus Post</title>

<link>http://computerbapu.blogspot.com</link>

<description> All computer related discussions</description>

<language>en-us</language>

<image>

<url>http://computerbapu.blogspot.com/myimage.jpg</url>

<title>C# hello world</title>

<link>http://computerbapu.blogspot.com</link>

</image>

<item>

<title>C# hello world</title>

<link>http://computerbapu.blogspot.com</link>

<description>console.writeline("i am good");</description>

</item>

</channel>

</rss>

Explaination :

title
A descriptive title for this channel. This should usually be the same as the content of the HTML element title on your main site page
(maximum length : 100)

link
A URI for the channel. This should be a link to the web site that originates the feed
(maximum length is 500 characters)

description
A description of the channel, usually answering the question "What's this site all about?" Limited to 500 characters.


copyright
Copyright notice for the channel

docs
Documentation for the RSS format used by the channel

lastBuildDate
Last time channel content changed, in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST (see http://www.ietf.org/rfc/rfc822.txt)

managingEditor
Email address of managing editor for the channel

pubDate
Publication date of channel, in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST (see http://www.ietf.org/rfc/rfc822.txt)

rating
Platform for Internet Content Selection (PICS) rating (http://www.w3.org/PICS/)

skipDays
Days to skip reading channel

skipHours
Hours to skip reading channel

textInput
A text input box for the channel, such as a search box (required children include title, description, name, and link)

webMaster
Email address of webmaster for the channel



For RSS 1.0 format
=================


XML API

<?xml version="1.0" encoding="UTF-8"?>

<rdf:RDF xmlns="http://purl.org/rss/1.0" xmlns:rdf="http://www.w3.org/1999/02/22

-rdf-syntax-ns#">

<channel rdf:about="http://computerbapu.blogspot.com/computerbapu.rss">

<title>Computer bapu</title>

<link>http://computerbapu.blogspot.com</link>

<description>Computer help</description>

<items>

<rdf:Seq>

<rdf:li rdf:resource="http://computerbapu.blogspot.com/myhelp.html"/>

</rdf:Seq>

</items>

</channel>

<item rdf:about="http://computerbapu.blogspot.com/myhelp.html">

<title>C# snippet for email</title>

<link>http://computerbapu.blogspot.com/email.html</link>

<description>hello world ()...</description>

</item>

</rdf:RDF>



Explaination:

rdf:RDF
The rdf:RDF element from the RDF namespace (http://www.w3.org/1999/02/22-rdf-syntax-ns#) is the document element. This element must have exactly one channel child and one or more item children (these elements are in the default namespace, http://purl.org/rss/1.0). The rdf:about attribute on channel, from the RDF namespace, identifies the feed with a URI.

title
A descriptive title for this channel.

link
A URI for the channel.

description
A description of the channel.

items
Contains the RDF elements Seq and li. The resource attribute on rdf:li contains a URI that identifies an item used later in the document

Two other possible children of channel are image and textinput, which link by means of rdf:resource attributes to other image and textinput elements, optionally used in the document as children of rdf:RDF (i.e., you can have one without the other). The image element links a graphic to the channel and must contain the trio title, link, and url; the textinput element contains a script or form that relates to the site and contains title, link, name, and description elements.


For RSS 2.0 format (quite popular now - successor of rss 0.91.)
===================================================


Example:

<rss version="2.0">

<channel>

<title>computer bapu</title>

<link>http://computerbapu.blogspot.com</link>
<pubDate>Mon, 05 Feb 2007 0:00:01 GMT</pubDate>

<description> computer help</description>


<item>

<title>RSS Help</title>

<link>http://computerbapu.blogspot.com/rsshelp.html</link>

<description>Latest News Feeds....</description>

</item>

<item>

<title>Atom Help</title>

<link>http://computerbapu.blogspot.com/atomhelp.html</link>

<description>Latest RSS News Feeds....</description>

</item>


</channel>

</rss>





Explaination:

Child element of channel:

title
Title of channel
(Required)

link
Link to channel
(Required)

description
Description of channel
(Required)

language
Language code for channel
(optional element)

image
Image that represents the channel (required children url, title, and link; optional children description, width, and height)
(optional element)

copyright
Copyright notice for the channel
(optional element)

managingEditor
Email address of managing editor
(optional element)

webMaster
Email address of webmaster
(optional element)

pubDate
Publication date of channel in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST; though not specified in RFC 822, a four-digit year is allowed (see http://www.ietf.org/rfc/rfc822.txt)
(optional element)

lastBuildDate
Last time channel content changed in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST; though not specified in RFC 822, a four-digit year is allowed (see http://www.ietf.org/rfc/rfc822.txt)
(optional element)

rating

Platform for Internet Content Selection (PICS) rating (http://www.w3.org/PICS/)
(optional element)

docs
Documentation for the RSS format used by channel
(optional element)

textInput
A text input box for the channel, such as a search box (required children include title, description, name, and link)
(optional element)

skipDays
Days to skip reading channel
(optional element)

skipHours
Hours to skip reading channel
(optional element)

category
One or more channel categories
(optional element)

generator
Name of generator program
(optional element)

cloud
Specifies a protocol for publishing and subscribing to feeds
(optional element)

ttl
Time to live in minutes
(optional element)


Child element of item:


title
Title of item

link
Link to item

description
Description of item

author
Email address of author of item (optional element)

category
One or more item categories (optional attribute domain)
(optional element)

comments
URL for comment page for item
(optional element)

enclosure
Describes an object attached to item (required attributes url, length, and type)
(optional element)

guid
Globally unique identifier
(optional element)

pubDate
Publication date in RFC 822 format
(optional element)

source
RSS channel the item came from (required attribute url)
(optional element)


Format of ATOM :
==============


<feed version="0.3" xmlns="http://purl.org/atom/ns#" xml:lang="en">

<title>Computer Bapu</title>

<link rel="alternate" type="text/html"

href="http://computerbapu.blogspot.com/"/>

<author>

<name>Computer Bapu SG</name>

</author>

<tagline>This discusses about computer topics</tagline>

<modified>2007-05-14T08:56:00-01:00</modified>

<entry>

<title>C# snippet</title>

<link rel="alternate" type="text/html"

href="http://computerbapu.blogspot.com/mySnippet.html"/>

<id>http://computerbapu.blogspot.com/mySnippet.html</id>

<issued>2007-04-14T08:56:00-01:00</issued>

<modified>2007-05-14T08:56:00-01:00</modified>

</entry>

</feed>


Title: title of the document. There can be only one title.
link: Link of the resource. There can be multiple links. Type denotes media type.
Author: Author of the resource. There can be one author container within which there can be name, url, email
tagline : feeds description

show detailed error in asp.net 2.0 web.config

show detailed error in asp.net 2.0 web.config
====================================


In web.config do the following

<customErrors mode="Off" />

This is handy for developers and testers in case when they are unable to exactly find the cause of an error. When in production this should not be used since it will show the entire detail to the laymen.

In such case use <customErrors mode="On"> to hide the detailed error.

You might want to keep show the error when run locally and hide the error when run remotely. You may achieve this using <customErrors mode="RemoteOnly">


Also if you want to redirect to a particular page when there is a error then you might use the below option:

<customErrors mode="On" defaultRedirect="ErrorTemplate.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>


what a basic hardware technician / pc technician must know

what a basic hardware technician / pc technician must know :

BASICS:

Hardware Industry
General Concepts about Hardware Parts
Hardware Jargon
Hardware components (detail discussion)
- motherboards, cpu, ram, drives, Add-on Cards, BIOS details, different types of cards available, cabinets etc
Power Supply
Peripherals latest rates and commercial information
Handling hardware components
Hardware repairing and assembling tools
Peripheral Drivers


HARDWARE INSTALLATIONS:

Hardware Assembling
Assembling Steps and Procedures
Testing of H/W before Assembling
Installation of External Peripherals such as printers, modem, LAN card, joystick, UPS, scanner, webcam etc.
Core Details:
Fixing of Mother Board, Cards etc.
Connecting Jumper Wires, Checking of AC/DC voltage, Serviceability Checks, Wire setting, Power LED-ON , Speaker Beep, Memory Testing, Error Codes.
Upgrading old pc into latest pc

PREVENTIVE MAINTAINANCE:

Hardisk Maintenance, Printer Maintenance, other peripheral maintenance briefings
Use of UPS
Use of Stabilizer
Cleaning Techniques: Internal System Components & Peripheral Components
Antivirus software

TROUBLESHOOTING:

Do and Don’t of Assembling
Various Jumpers/switches
ROM BIOS configuration
Compatible Hardware Part identification to prevent mismatch with older pc or pc with different motherboard or cpu
CD ROM & other peripheral repairing (core)
Printer cartrage fitting
Checking of COM and LPT ports
Connecting PDA’s to computer via port
Other repairing Techniques
Finding defective components (most probable problems for a particular fault)
Repairing boot faults
Finding input device problem, drives problem, power problems, modem problems, boot problems, adapter card and pc card problem etc.
Partitioning techniques
OS installations, formatting, dual boot
Modem , sound and display driver installtion
Defragmentation and Scandisk
Troubleshooting utilities and software
Troubleshooting remotely and handling people
Data Transfer Techniques


NETWORK BASICS:

LAN setup
Hardisk data transfer
Internet Connection – dial-up, cable connection, using mobile phone
cabling, labtop overview


Get a A+ certification in short. You may also give an exam at brainbench and check whether you pass / fail..The above you can easily cover in 1 and a half month or even less


php simple paging example

php simple paging example
======================


The below code is self explanatory for a coder

<?
function Connect() {

$hostname = "localhost";
$database = "mmm";
$db_login = "";
$db_pass = "";

$ad_login = "";
$ad_pass = "";


$dbase_link = mysql_connect($hostname, $db_login, $db_pass) or die("Could not connect");
mysql_select_db($database) or die("Could not select database");

}
?>

<?php

//Set the page size
$PageSize = 10;
$StartRow = 0;

//Set the page no
if(empty($_GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}

//Set the counter start
if($PageNo % $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}

//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);
?>

<html>
<head>
<title>Paging Example By Nasa</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="include/style.css" type="text/css">
</head>
<?php

connect();
//query trick
$strSQL = "select * from bike where Type='$type'
AND Brand='$brand' AND City='$city' ORDER BY area LIMIT $StartRow,$PageSize";

$result = mysql_query($strSQL) or die("Query failed");
$TRecord = mysql_query("SELECT * FROM bikes");

//Total of record
$RecordCount = mysql_num_rows($TRecord);

//Set Maximum Page
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}
?>
<body>
<table width="100%" border="0" class="InternalHeader">
<tr>
<td width="24%">LIST.....</td>
<td width="76%">
<div align="right">
<?php print "$RecordCount record(s) founds - You are at page $PageNo of $MaxPage" ?></div>
</td>
</tr>
</table>
<br>
<table width="100%" border="0" class="NormalTableTwo">
<tr>
<td width="4%">ID</td>
<td width="36%">NAME ID</td>
<td width="20%">CONTACT</td>
<td width="20%">PHONE</td>
</tr>
<?php
$i = 1;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$bil = $i + ($PageNo-1)*$PageSize;
?>
<tr>
<td width="4%"><?php echo $bil ?></td>
<td width="36%"><?php echo $row["ID"] ?></td>
<td width="20%"><?php echo $row["Name"] ?></td>
<td width="20%"><?php echo $row["contact"] ?></td>
<td width="20%"><?php echo $row["phone"] ?></td>
</tr>
<?php
$i++;
}?>
</table><br>
<table width="100%" border="0" class="InternalHeader">
<tr>
<td>

<div align="center">
<?php
//Print First & Previous Link is necessary
if($CounterStart != 1){
$PrevStart = $CounterStart - 1;
print "<a href=ok1.php?PageNo=1>First </a>: ";
print "<a href=ok1.php?PageNo=$PrevStart>Previous </a>";
}
print " [ ";
$c = 0;

//Print Page No
for($c=$CounterStart;$c<=$CounterEnd;$c++){
if($c < $MaxPage){
if($c == $PageNo){
if($c % $PageSize == 0){
print "$c ";
}else{
print "$c ,";
}
}elseif($c % $PageSize == 0){
echo "<a href=ok1.php?PageNo=$c>$c</a> ";
}else{
echo "<a href=ok1.php?PageNo=$c>$c</a> ,";
}//END IF
}else{
if($PageNo == $MaxPage){
print "$c ";
break;
}else{
echo "<a href=ok1.php?PageNo=$c>$c</a> ";
break;
}//END IF
}//END IF
}//NEXT

echo "] ";

if($CounterEnd < $MaxPage){
$NextPage = $CounterEnd + 1;
echo "<a href=ok1.php?PageNo=$NextPage>Next</a>";
}

//Print Last link if necessary
if($CounterEnd < $MaxPage){
$LastRec = $RecordCount % $PageSize;
if($LastRec == 0){
$LastStartRecord = $RecordCount - $PageSize;
}
else{
$LastStartRecord = $RecordCount - $LastRec;
}

print " : ";
echo "<a href=ok1.php?PageNo=$MaxPage>Last</a>";
}
?>
</div>
</td>
</tr>
</table>
<?php
mysql_free_result($result);
mysql_free_result($TRecord);
?>
</body>
</html>

Quickly make a deploy folder using ASP.NET 2.0.

Quickly make a deploy folder using ASP.NET 2.0.
=======================================


run the below command a folder will be created (as specified). Also mysite is the path of your website

asp_compiler -v mysite c:\folder -f -u

Register an activex component

Register an activex component

look for regsvr32.exe in system/system32 folder in windows (note down the path)

Open dos prompt and do it!

C:\system32>regsvr32 c:\youractivex.ocx

A messagebox will appear if the ocx gets registered.

List tables in ms sql server

List tables in ms sql server
=====================


For ms sql
sp_help

For my sql it is
show tables

List tables in ms sql server

List tables in ms sql server
=====================


For ms sql
sp_help

For my sql it is
show tables

List fields in ms sql server

List fields in ms sql server
=====================


for my sql:
describe tablename

for ms sql server:
sp_help tablename

list database in ms sql server

list database in ms sql server
=======================


Just type out following command in ms sql server query analyzer

sp_databases

For My sql type out show databases


if you want to use it use:
use nameofthedatabase

Datagrid to excel using ASP.NET

Datagrid to excel using ASP.NET
===========================


Two things to be done:
1) Fetch data from datasource and bind to datagrid
2) Pass the datagrid to ExportToExcel function. The content type should be application/vnd.ms-excel



//convert to excel from httpresponse
private void ExportToExcel(DataGrid dgExport, HttpResponse response )
{
response.Clear();
response.Charset = "";
response.ContentType ="application/vnd.ms-excel";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.Html32TextWriter htmlWrite = new System.Web.UI.Html32TextWriter(stringWrite) ;

DataGrid dg=new DataGrid();
dg=dgExport;

dg.GridLines =GridLines.None;
dg.HeaderStyle.Font.Bold =true;
dg.HeaderStyle.ForeColor =System.Drawing.Color.Red;
dg.ItemStyle.ForeColor =System.Drawing.Color.Black;


dg.DataBind();
dg.RenderControl(htmlWrite);
response.Write(stringWrite.ToString());
response.End();

}

//fetch date from datasource and bind to grid

private void cmdMakeExcel_Click(object sender, System.EventArgs e)
{
try
{
string strSQL = txtQuery.Text.ToString();
SqlDataAdapter daa = new SqlDataAdapter(strSQL, Connection.getConn());


DataSet Dsss = new DataSet();

daa.Fill(Dsss);
daa.FillSchema(Dsss,SchemaType.Mapped);
DataGrid Dss=new DataGrid();

Dss.DataSource = Dsss;
Dss.DataBind();

ExportToExcel(Dss,Response);
}
catch
{
Response.Write("Could Not Process");
}
}

console based input in C#

console based input in C#
====================


string userName;

Console.WriteLine ("Please Enter your name : ");
userName= Console.ReadLine();
Console.WriteLine ("Welcome {0} ",userName);



Please find that Console.ReadLine() is something like scanf in C language

PREFIX TO INFIX in C

PREFIX TO INFIX in C

#include<stdio.h>
struct stack
{
char data[7][16];
int tos;
}s;


main()
{
char prefix[20];
clrscr();
printf("PLEASE ENTER THE PREFIX EXPRESSION:");
scanf("%s",prefix);
preinf(prefix);
getch();
}

preinf(char prefix[])
{
int length,i,len;
char str1[20];
length=strlen(prefix);
for(i=length;i>=0;i--)
{
switch(prefix[i])
{
case '+':
case '-':
case '*':
case '/':
case '^':
{
str1[0]='(';
str1[1]='\0';
strcat(str1,pop());
len=strlen(str1);
str1[len]=prefix[i];
str1[++len]='\0';
strcat(str1,pop());
len=strlen(str1);
str1[len]=')';
str1[++len]='\0';
push(str1);
break;
}
default:
{
str1[0]=prefix[i];
str1[1]='\0';
push(str1);
}
}
}
printf("\nTHE INFIX EXPRESSION IS:%s",pop());
}

push(char string[])
{
strcpy(s.data[s.tos],string);
s.tos++;
}

pop()
{
s.tos--;
return(s.data[s.tos]);
}

PROGRAMME TO CONVERT INFIX EXPRESSION TO POSTFIX

/* PROGRAMME TO CONVERT INFIX EXPRESSION TO POSTFIX
EXPRESSION */


#include<stdio.h>
# define size 20
struct stk
{
char ele[size];
int tos;
};
typedef struct stk stack;
stack s;
main()
{
int len;
char infix[20],ch;
clrscr();
printf("PLEASE ENTER INFIX EMPRESSION:");
scanf("%s",infix);
len=strlen(infix);
infix[len]=')';
infix[++len]='\0';
printf("\n THE POSTFIX EXPRESSION IS:");
infpre(infix);
getch();
}

infpre(char infix[20])
{
int length,i,a,b;
char ch;
s.tos=0;
s.ele[s.tos]='(';
length=strlen(infix);
for(i=0;i<length;i++)
{
switch(infix[i])
{
case '*':
case '+':
case '-':
case '/':
case '^':
case '(':
case '$':
{
a=isp(s.ele[s.tos]);
b=icp(infix[i]);
if(a>=b)
{
ch=pop();
printf("%c",ch);
s.tos++;
push(infix[i]);
}
else
{
s.tos++;
push(infix[i]);

}
break;
}
case ')':
{
ch=pop();
while(ch!='(')
{
printf("%c",ch);
ch=pop();
}
break;
}
default:
printf("%c",infix[i]);
}}}

push(char ch)
{
s.ele[s.tos]=ch;
}

pop()
{
char ch;
ch=s.ele[s.tos];
s.tos--;
return(ch);
}

int isp(char a)
{
switch(a)
{
case '^':return(3);
case '*':
case '/':return(2);
case '+':
case '-':return(1);
case '(':return(0);
case '$':return(5);
}}

int icp(char a)
{
switch(a)
{
case '^':return(4);
case '*':
case '/':return(2);
case '+':
case '-':return(1);
case ')':return(4);
case '$':return(5);
}}

PREFIX TO POSTFIX in C

/* PREFIX TO POSTFIX in C*/

#include<stdio.h>
#include<string.h>
#define size 10
char ch;
struct stk
{
char ele[size];
int top;
}s;
main()
{
int length;
char infix[20];
clrscr();
printf("PLEASE ENTER THE PREFIX EXPRESSION:");
scanf("%s",infix);
length=strlen(infix);
infix[length]=')';
infix[++length]='\0';
printf("\nTHE POSTFIX MESSAGE IS:");
infpost(infix);
getch();
}
infpost(char infix[])
{
int a,b,length,i,count=0;
s.top=0;
s.ele[s.top]='(';
s.top++;
length=strlen(infix);
for(i=0;i<length;i++)
{
switch(infix[i])
{
case '*':
case '^':
case '/':
case '+':
case '-':
case '(':
{
a=isp(s.ele[s.top]);
b=icp(infix[i]);
/*printf("\nisp=%d icp=%d",a,b);
getch();*/
if(a>=b)
{
ch=pop();
printf("%c",ch);
s.top++;
push(infix[i]);
if(i==10)
break;
if(s.top==2)
{
s.top--;
ch=pop();
printf("%c",ch);
s.ele[1]=s.ele[2];
s.top=1;
}
}
else
{
if(count!=0) s.top++;
push(infix[i]);
count++;
break;
}}
case ')':
{
ch=pop();
while(ch!='(')
{
printf("%c",ch);
ch=pop();
}
break;
}
default:
printf("%c",infix[i]);
} } }


int push(char ch)
{
if(s.top==size-1)
{
printf("stack full \n");
return(0);
}
s.ele[s.top]=ch;
return(1);
}
int pop()
{
if(s.ele[s.top]==-1)
{
printf("stack empty");
return(0);
}
ch=s.ele[s.top];
s.top--;
return(ch);
}
int isp(char a)
{
switch(a)
{
case '^': return(3);
case '*':
case '/': return(2);
case '+':
case '-':return(1);
case '(':return(0);
}
}

int icp(char a)
{
switch(a)
{
case '^': return(4);
case '*':
case '/': return(2);
case '+':
case '-':return(1);
case ')':return(4);
}
}

PROGRAMME TO CONVERT INFIX TO PREFIX

/* PROGRAMME TO CONVERT INFIX TO PREFIX */


#include<stdio.h>
# define size 20
struct stk
{
char ele[size];
int tos;
};
typedef struct stk stack;
stack s;
main()
{
int len;
char infix[20],ch;
clrscr();
printf("PLEASE ENTER INFIX EMPRESSION:");
scanf("%s",infix);
len=strlen(infix);
infix[len]=')';
infix[++len]='\0';
printf("\n THE PREFIX EXPRESSION IS:");
infpre(infix);
getch();
}

infpre(char infix[20])
{
int length,i,a,b,len;
char ch,prefix[20],temp[20];
prefix[0]='\0';
s.tos=0;
s.ele[s.tos]='(';
length=strlen(infix);
for(i=0;i<length;i++)
{
switch(infix[i])
{
case '*':
case '+':
case '-':
case '/':
case '^':
case '(':
{
a=isp(s.ele[s.tos]);
b=icp(infix[i]);
if(a>=b)
{
ch=pop();
temp[0]=ch;
temp[1]='\0';
strcat(temp,prefix);
strcpy(prefix,temp);
s.tos++;
push(infix[i]);
}
else
{
s.tos++;
push(infix[i]);
}
break;
}
case ')':
{
ch=pop();
while(ch!='(')
{
temp[0]=ch;
temp[1]='\0';
strcat(temp,prefix);
strcpy(prefix,temp);
ch=pop();
}
break;
}
default:
{
len=strlen(prefix);
prefix[len]=infix[i];
prefix[++len]='\0';
}
}}
printf("%s",temp);
}

push(char ch)
{
s.ele[s.tos]=ch;
}

pop()
{
char ch;
ch=s.ele[s.tos];
s.tos--;
return(ch);
}

int isp(char a)
{
switch(a)
{
case '^':return(3);
case '*':
case '/':return(2);
case '+':
case '-':return(1);
case '(':return(0);
}}

int icp(char a)
{
switch(a)
{
case '^':return(4);
case '*':
case '/':return(2);
case '+':
case '-':return(1);
case ')':return(4);
}}

FORMING A TREE USING PREFIX EXPRESSION

/* FORMING A TREE USING PREFIX EXPRESSION AND THEN PREFORM
ALL THE TRAVERSALS(RECURSIVE) */


#include<stdio.h>
#include<ctype.h>
struct tree
{
char data;
struct tree *left,*right;
};
typedef struct tree btree;
char prefix[20];
btree *stack[20];
int top;
main()
{
btree *create(void);
void inorder(btree *temp);
void preorder(btree *temp);
void postorder(btree *temp);
void push(btree *temp);
btree *pop(void);
btree *root;
clrscr();
printf("PLEASE ENTER THE PREFIX EXPRESSION:");
gets(prefix);
root=create();
printf("\nTHE INORDER TRAVERSAL IS:");
inorder(root);
printf("\nTHE PREORDER TRAVERSAL IS:");
preorder(root);
printf("\nTHE POSTORDER TRAVERSAL IS:");
postorder(root);
getch();
}

btree *create(void)
{
btree *head,*temp,*temp1;
int i=0,n;
top=-1;
head=(btree*)malloc(sizeof(btree));
temp=head;
temp->data=prefix[i];
i++;
temp->right=temp->left=NULL;
push(temp);
n=strlen(prefix);
while(top!=-1)
{
while(!isalnum(prefix[i]))
{
temp=pop();
temp1=(btree*)malloc(sizeof(btree));
temp1->right=temp1->left=NULL;
temp->left=temp1;
temp1->data=prefix[i];
i++;
push(temp);
push(temp1);
}
temp1=(btree*)malloc(sizeof(btree));
temp=pop();
temp->left=temp1;
temp1->data=prefix[i];
temp1->left=temp1->right=NULL;
push(temp);
do {
temp=pop();
i++;
temp1=(btree*)malloc(sizeof(btree));
temp->right=temp1;
temp1->data=prefix[i];
temp1->right=temp1->left=NULL;
if(!isalpha(prefix[i]))
{i++;
push(temp1);
break;}
}while(top!=-1);
}
return(head);
}

void push(btree *temp)
{
top++;
stack[top]=temp;
return;
}
btree *pop(void)
{
return(stack[top--]);
}

void inorder(btree *temp)
{
if(temp)
{
inorder(temp->left);
putch(temp->data);
inorder(temp->right);
}
return;
}

void preorder(btree *temp)
{
if(temp)
{
putch(temp->data);
preorder(temp->left);
preorder(temp->right);
}
return;
}

void postorder(btree *temp)
{
if(temp)
{
postorder(temp->left);
postorder(temp->right);
putch(temp->data);
}
return;
}

PROGRAM TO SWAP TWO NUMBERS WITHOUT USING A THIRD VARIABLE IN C PROGRAMMING

PROGRAM TO SWAP TWO NUMBERS WITHOUT USING A THIRD VARIABLE IN C PROGRAMMING

This eveyone computer science student must have encountered.

void main()
{
int a,b;
printf("PLEASE ENTER THE TWO NUMBERS:");
scanf("%d %d",&a,&b);
/*little bit of maths*/
a=a+b;
b=a-b;
a=a-b;
printf("THE SWAPPED NUMBERS ARE:");
printf("%d %d",a,b);
getch();
}

Stack implementation using Array - c program (stack operation)

Stack implementation using Array - c program (stack operation)
===================================================


#include <stdio.h>
#include <conio.h>
#define size 10

int top = -1;
int stack[size];
int flag = 0;

void push (int *,int);
int pop (int *);
int peep (int *,int);
int update (int *,int);
void display (int *);

void main ()
{
int info,popped_element,position,data,pos_update,update_element,update_data;
char ch;

clrscr ();

do
{
printf("\n\ni<-Insert(push), d<-Delete(pop),p<-peep,u<-update, q<-Quit\n");
fflush (stdin);
printf("\n\nEnter your choice: ");
scanf("%c",&ch);
switch (ch)
{
case 'i':
{
printf("\n\nEnter the element you want to push: ");
scanf("%d",&info);
push (stack,info);
display (stack);
break;
}

case 'd':
{
popped_element = pop(stack);

if (flag == 0)
printf("\n\nThe element popped is %d",popped_element);
if (flag == 1)
printf("\nStack Underflow");
display (stack);
break;
}

case 'p':
{
printf("\n\nEnter the position of the stack from which you want to peep the element: ");
scanf("%d",&position);
data = peep(stack,position);
if (flag == 1)
printf("\nInvalid choice\n");
else
printf("The element peeped is %d",data);
display (stack);
break;
}

case 'u':
{
printf("Enter the position of the stack from which you want to update the data: ");
scanf("%d",&pos_update);
update_element = update(stack,pos_update);
if (flag == 1)
printf("Data can't be updated due to some reason");
else
printf("The data updated is %d",update_element);
display (stack);
break;
}

case 'q':
exit(0);
}
}while (ch != 'q');

getch ();
}

void push (int stack[],int info)
{
if (top == size-1)
printf("\nStack Overflow");
else
{
top++;
stack[top] = info;
}
}

int pop (int stack[])
{
int popped_element;
if (top == -1)
flag = 1;
else
{
flag = 0;
popped_element = stack[top];
top--;
}
return (popped_element);
}

void display (int stack[])
{
int i;
printf("\n\nThe contents of the stack are:\n");
for (i = top ; i >= 0 ; i--)
printf("%d ",stack[i]);
}

int peep (int stack[],int i)
{
int data;
if (top - i + 1 < 0)
flag = 1;
else
{
flag = 0;
data = stack[top-i+1];
}
return (data);
}

int update(int stack[],int pos)
{
int old_data;
if (top - pos + 1 < 0)
flag = 1;
else
{
flag = 0;
old_data = stack[top-pos+1];
printf("Enter the data you want to insert: ");
scanf("%d",&stack[top-pos+1]);
}
return (old_data);
}


Stack implementation using link list - c program
==============================

#include <stdio.h>
#include <conio.h>
struct Stack
{
int info;
struct Stack *next;
};
typedef struct Stack node;
node *first = NULL;
node *push (node *);
node *pop (node *);
void display (node *);

void main ()
{
char ch;

clrscr ();

do
{
fflush (stdin);
printf("\n\ni<-insert(push), d<-delete(pop), q<-quit\n");
printf("\n\nEnter the choice: ");
scanf("%c",&ch);
switch (ch)
{
case 'i':
{
first = push (first);
printf("\n\nAfter the push operation the stack is as follows:\n");
display (first);
break;
}

case 'd':
{
first = pop (first);
printf("\n\nAfter the pop operation the stack is as follows:\n");
display (first);
break;
}

case 'q':
exit (0);
}
}while (ch != 'q');

getch ();
}

node *push(node *first)
{
node *data;
data = (node *)malloc(sizeof(node));
printf("\nEnter the data to be inserted: ");
scanf("%d",&data->info);
data->next = first;
first = data;
return (first);
}

node *pop (node *first)
{
node *temp;
if (first == NULL)
printf("\n\nSTACK IS EMPTY\n");
else
{
temp = (node *)malloc(sizeof(node));
temp = first;
first = first->next;
printf("\nThe element deleted is %d",temp->info);
free (temp);
}
return (first);
}

void display (node *first)
{
while (first != NULL)
{
printf("%d ",first->info);
first = first->next;
}
}

PROGRAMME TO ENTER GRAPHICS MODE AND PRINT SOMETHING

PROGRAMME TO ENTER GRAPHICS MODE AND PRINT SOMETHING

#include<stdio.h>
#include<graphics.h>
main()
{
int ga=DETECT,gm;
initgraph(&ga,&gm," ");
settextstyle(0,0,100);
outtextxy(70,150,"PRAGATI PRAKASHAN");
getch();
closegraph();
}

PROGRAMME TO REVERSE A DOUBLY LINKED LINK LIST

/* PROGRAMME TO REVERSE A DOUBLY LINKED LINK LIST */


#include<stdio.h>
struct llist
{
int val;
struct llist *next,*prev;
};
typedef struct llist list;

main()
{
list *create(void);
void reverse(list *temp);
list *root;
clrscr();
printf("PLEASE ENTER THE LIST,ENTER -99 TO END:");
root=create();
reverse(root);
getch();
}

list *create(void)
{
list *head,*temp,*temp1;
int data;
head=(list*)malloc(sizeof(list));
temp=head;
head->prev=NULL;
do
{
scanf("%d",&data);
if(data==-99)
return(head);
temp1=(list*)malloc(sizeof(list));
temp1->val=data;
temp->next=temp1;
temp1->prev=temp;
temp1->next=NULL;
temp=temp1;
}while(1);
}

void reverse(list *head)
{
list *t1,*t2,*t3;
t1=head->next;
t2=t1->next;
t3=head;
do
{
t1->next=t3;
t1->prev=NULL;
head->next=t2;
t3->prev=t1;
t3=t1;
t1=t2;
t2=t2->next;
}while(t1!=NULL);
printf("\nTHE REVERSED LIST IS:");
t1=t3;
while(t1!=head)
{
printf(" %d",t1->val);
t1=t1->next;
}
return;
}

Link list programs in C (single, doubly and circular link list)

Link list programs in C (single, doubly and circular link list)
--------------------------------------------------------------------------------------



Singly link list
=================


#include <stdio.h>
#include <malloc.h>
#include <conio.h>

struct list
{
int info;
struct list *next;
};
typedef struct list node;

void main ()
{
node *first;
int choice;
node *create (node *);
node *insert (node *);
node *del (node *);
void display (node *);

clrscr ();

while (1)
{
printf("\n\nYou have following choices:\n");
printf("1. Create List\n");
printf("2. Insert a node in the List\n");
printf("3. Delete a node from the List\n");
printf("4. Display the List\n");
printf("5. Termenate the Program\n");
printf("Enter your choice: ");
scanf ("%d",&choice);
switch (choice)
{
case 1:
first = create(first);
break;
case 2:
first = insert (first);
break;
case 3:
first = del (first);
break;
case 4:
display (first);
break;
case 5:
exit (0);
}
}
}

node *create (node *first)
{
node *new1 = NULL,*l;
int i;
first = NULL;
printf("\n\nTHE INPUT IS:\n");
printf("-------------\n\n");
while(1)
{
printf("\nEnter -1 to break.....\n");
printf("Enter the node you want to enter in ascending order: ");
scanf("%d",&i);

if (i == -1)
break;

else
{
new1 = ((node *) malloc (sizeof (node)));
new1 -> info = i;
if(first == NULL)
{
first = l = new1;
}
else
{
l -> next = new1;
l = new1;
}
l -> next = NULL;
}
}
return (first);
}

void display (node *first)
{
printf("\n\nTHE OUTPUT IS:\n");
printf("--------------\n\n");
while (first != NULL)
{
printf("%d -> ",first -> info);
first = first -> next;
}
printf("NULL");
}

node *insert (node *first)
{
node *l, *new1;
l = first;
new1 = (node *) malloc (sizeof (node *));
printf("Enter the node: ");
scanf("%d",&new1 -> info);
if (first == NULL)
{
first = new1;
first -> next = NULL;
}
else
{
if (new1 -> info < first -> info)
{
new1 -> next = first;
first = new1;
}
else
{
while (l -> next -> info < new1 -> info && l -> next != NULL)
l = l -> next;
new1 -> next = l -> next;
l -> next = new1;
l = new1;
}
}
display (first);
return (first);
}

node *del (node *first)
{
int n;
node *l = first, *new1, *temp;
printf("Enter the information: ");
scanf("%d",&n);
if (first == NULL)
printf("\nLIST IS EMPTY\n");
else
{
if (first -> info == n)
{
temp = first;
first = first -> next;
free (temp);
}
else
{
while (l -> next -> info != n && l -> next != NULL)
l = l -> next;
if (l -> next == NULL)
printf("\nINFORMATION IS NOT PRESENT\n");
else
{
temp = l -> next;
l -> next = l -> next -> next;
free(temp);
}
}
}
display (first);
return (first);
}

Doubly Link List
===============

#include <stdio.h>
#include <alloc.h>
#include <conio.h>

struct Double
{
int info;
struct Double *next;
struct Double *previous;
};
typedef struct Double node;

node *create(node *);
node *insert(node *);
node *del(node *);
void display (node *);

node *first = NULL;

void main ()
{
int choice;

clrscr ();

while (1)
{
printf("\n\nYou have following choices:\n");
printf("1. Create List\n");
printf("2. Insert a node in the List\n");
printf("3. Delete a node from the List\n");
printf("4. Display the List\n");
printf("5. Termenate the Program\n");
printf("Enter your choice: ");
scanf ("%d",&choice);
switch (choice)
{
case 1:
first = create(first);
break;
case 2:
first = insert (first);
break;
case 3:
first = del (first);
break;
case 4:
display (first);
break;
case 5:
exit (0);
}
}
}

node *create (node *first)
{
node *new1,*l = NULL;
int i;
//first -> next = first -> previous = NULL;
while (1)
{
printf("Enter the information(-1 to Exit): ");
scanf("%d",&i);
if (i == -1)
break;
new1 = (node *)malloc(sizeof(node));
new1 -> info = i;
if (first == NULL)
{
first = l = new1;
first -> next = first -> previous = NULL;
}
else
{
new1 -> previous = l;
l -> next = new1;
l = new1;
}
l -> next = NULL;
}
return (first);
}

void display (node *first)
{
node *l;
l = first;
printf("\n\n\t\tDOUBLY LINK LIST:\n");
printf("\t\t-----------------\n");
printf("NULL");
for (l = first ; l != NULL ; l = l -> next)
printf(" <- %d -> ",l -> info);
printf("NULL");
}

node *insert (node *first)
{
node *new1,*l=NULL;
new1 = (node *)malloc(sizeof(node));
printf("\n\nEnter the node you want to insert: ");
scanf("%d",&new1->info);
if (first == NULL)
{
printf("Empty list. New list will be created.");
first = new1;
first->next = NULL;
first->previous = NULL;
}
else
{
if (new1->info < first->info)
{
new1->next = first;
new1->previous = NULL;
first->previous = new1;
first = new1;
}
else
{
l = first;
while (l->next->info < new1->info && l->next != NULL)
l = l->next;
new1->next = l->next;
l->next = new1;
new1->previous = l;
l = new1;
}
}
display (first);
return (first);
}

node *del (node *first)
{
int del_info;
node *l=NULL,*temp;
printf("\n\nEnter the information to be deleted: ");
scanf("%d",&del_info);
if (first == NULL)
printf("The List is Empty.");
else
{
if (first->info == del_info)
{
temp = first;
first = first->next;
first->previous = NULL;
free(temp);
}
else
{
l = first;
while (l->info < del_info && l->next != NULL)
l = l->next;
l->previous->next = l->next;
l->next->previous = l->previous;
}
}
display (first);
return (first);
}

Circular link list
=================


#include <stdio.h>
#include <malloc.h>
#include <conio.h>

///////////////////////STRUCTURE DEFINITION////////////////////////////////
struct cir_link_list
{
int info;
struct cir_link_list *next;
};
typedef struct cir_link_list node;

///////////////////////VARIABLE DECLARATION////////////////////////////////
node *first=NULL;
int info;

///////////////////////FUNCTION DECLARATION////////////////////////////////
node *create (node *);
void display (node *);
node *insert (node *);
node *del (node *);
int count = 0;

///////////////////////VOID MAIN () DEFINITION/////////////////////////////
void main ()
{
int choice;

clrscr ();

while (1)
{
printf("\n\nYou have following choices:\n");
printf("1. Create List\n");
printf("2. Insert a node in the List\n");
printf("3. Delete a node from the List\n");
printf("4. Display the List\n");
printf("5. Termenate the Program\n");
printf("Enter your choice: ");
scanf ("%d",&choice);
switch (choice)
{
case 1:
first = create(first);
break;
case 2:
first = insert (first);
break;
case 3:
first = del (first);
break;
case 4:
display (first);
break;
case 5:
exit (0);
}
}
}

///////////////////////CREATION OF CIRCULAR LINK LIST//////////////////////
node *create (node *first)
{
int i;
node *new1,*l=NULL;

while (1)
{
printf("Enter -1 to break........\n");
printf("Enter the node: ");
scanf("%d",&i);
if (i == -1)
{
l->next=first;
break;
}
else
{
new1 = ((node *)malloc(sizeof(node)));
new1 -> info = i;
if (first == NULL)
{
first = l = new1;
}
else
{
l->next=new1;
l=new1;
}
}
count++;
}
return (first);
}

///////////////////////DISPLAY OF CIRCULAR LINK LIST///////////////////////
void display (node *first)
{
int i;
for (i=0 ; i< count ; i++)
{
printf("%d -> ",first->info);
first = first -> next;
}
}

node *insert (node *first)
{
int i = 0;
node *l, *new1;
l = first;
new1 = (node *) malloc (sizeof (node *));
printf("\nEnter the node: ");
scanf("%d",&new1 -> info);
if (first == NULL)
{
first = new1;
first -> next = first;
}
else
{
if (new1 -> info < first -> info)
{
new1 -> next = first;
first = new1;
}
else
{
while (l -> next -> info < new1 -> info && l -> next != first && i <= count)
{
l = l -> next;
i++;
}
if (l -> next == first i > count)
{
new1 -> next = l -> next;
l -> next = new1;
l = new1;
}
new1 -> next = l -> next;
l -> next = new1;
}
}
count++;
display (first);
return (first);
}

node *del (node *first)
{
int n,i=0;
node *l = first, *new1, *temp;
printf("\nEnter the information: ");
scanf("%d",&n);
if (first == NULL)
printf("\nLIST IS EMPTY\n");
else
{
if (first -> info == n)
{
temp = first;
first = first -> next;
free (temp);
}
else
{
while (l -> next -> info != n && l -> next != first && i <= count)
{
l = l -> next;
i++;
}
if (l -> next == first i > count)
{
printf("\nINFORMATION IS NOT PRESENT\n");
goto jmp;
}
else
{
temp = l -> next;
l -> next = l -> next -> next;
free(temp);
}
}
}
count --;
jmp:
display (first);
return (first);
}

insert and delete queue in C++ (queue operation)

insert and delete queue in C++ (queue operation)
=======================================


# include<iostream.h>
# include<conio.h>
# include<string.h>
# include<ctype.h>
# include<process.h>
# define size 10
class Queue
{
public: int rear, front;
int ch;
int q[size];

public: Queue()
{
rear = front = 0;
}
void Insert_queue();
void Delete_queue();
void Display_queue();

};

// Function to create queue
void Queue :: Insert_queue()
{
cout<<"\n Input the element :";
cin>>ch;
if(rear < size)
{
rear ++;
q[rear] = ch ;
if(front == 0)
front = 1;
}
else
cout<<"\nOverflow";
}

// Function to perform delete operation
void Queue :: Delete_queue() //char q[], char ch)
{
if (front == 0)
{
cout<<"\nUnderflow";
return ;
}
else
{
ch = q[front];
cout<<"\nElement deleted :"<<ch;
}
if(front == rear)
{
front = 0;
rear = 0;
}
else
front = front + 1;
}

// Output function
void Queue :: Display_queue() //char q[])
{
if (front == 0)
return;
for( int i = front ; i <= rear; i++)
cout<<" "<<q[i];
}

//Function main
void main()
{
Queue Q;
int k = 0;
char choice;

do
{
cout<<"\nInsert->i Delete->d Quit->q:";
cout<<"\nInput the choice : ";
do
{
cin>>choice;
choice = tolower(choice);
}
while(strchr("idq",choice)==NULL);
cout<<"Your choice is ->"<<choice;
switch(choice)
{
case 'i' :
Q.Insert_queue();
cout<<"\nQueue after inserting ";
Q.Display_queue();
break;

case 'd' :
Q.Delete_queue();
cout<<"\nQueue content after deleteion is as follows:\n";
Q.Display_queue();
break;
case 'q':
k = 1;
}
}
while(!k);
}

Demonstrate use of mouse in C (assembly)

Demonstrate use of mouse in C (assembly)

/* PROGRAMME TO DEMONSTRATE USE OF MOUSE IN C LANGUAGE */
/* FORMING OUR OWN CURSOR */

#include<stdio.h>
#include<graphics.h>
#include<dos.h>
union REGS inregs;
struct SREGS sinregs;
static int mask[]={
0xe1ff,
0xe1ff,
0xe1ff,
0xe1ff,
0xe1ff,
0xe000,
0xe000,
0xe000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x1e00,
0x1200,
0x1200,
0x1200,
0x13ff,
0x1249,
0x1249,
0xf249,
0x9001,
0x9001,
0x9001,
0x8001,
0x8001,
0x8001,
0xffff
};
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
cleardevice();
inregs.x.ax=0;
int86(0x33,&inregs,&inregs);
inregs.x.ax=1;
int86(0x33,&inregs,&inregs);
inregs.x.ax=9;
inregs.x.bx=5;
inregs.x.cx=0;
inregs.x.dx=(int)mask;
segread(&sinregs);
sinregs.es=sinregs.ds;
int86x(0x33,&inregs,&inregs,&sinregs);
getch();
closegraph();
}

A simple ADO DB connection in ASP

A simple ADO DB connection in ASP
=============================


* Create a Connection instance
* Open Connection with provider details either sql server/ms access
* Create a Recordset instance
* Open Recordset with your sql statement
* loop it to display the fetched query


Here is your code to do so :

<body>
<%
Dim DB
Set DB = Server.CreateObject("ADODB.Connection")
DB.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _
"C:\My documents\students.mdb")

Set Rs = Server.CreateObject("ADODB.Recordset")

Rs.Open "Select * from students",DB

If Rs.EOF Then
Response.Write "There are no records"
Else
Rs.MoveFirst

While Not Rs.EOF
Response.Write Rs.Fields("FirstName")
Response.Write Rs.Fields("LastName")
Response.Write "<hr/>"
Rs.MoveNext
Wend
End If

%>
</body>
</html>

'If you want to add new record using ado. plz look at the following:

Rs.AddNew
Rs("FirstName")="XMan"
Rs("LastName")="XFemale"
Rs("DateOfBirth") = CDate("25 july 1981")
Rs.Update




Circular queue in C - program

Circular queue in C (program)
========================


#include <stdio.h>
#include <conio.h>
#define size 10

int queue[size];
int front = 0;
int rear = 0;
int flag = 0;

int insert (int []);
int del (int []);
void display (int []);

void main ()
{
char ch;
int insert_element,del_element;

clrscr ();

do
{
fflush (stdin);
printf("\n\ni<-insert, d<-delete, q<-quit\n");
printf("\n\nEnter your choice: ");
scanf("%c",&ch);
switch (ch)
{
case 'i':
{
if (flag == 1)
printf("\nOVERFLOW\n");
else
{
insert_element = insert(queue);
printf("\n\nElement inserted is %d",insert_element);
printf("\n\nAfter the insertion the contents of the queue are:\n");
display (queue);
}
break;
}

case 'd':
{
del_element = del (queue);
if (flag == 1)
printf("\nUNDERFLOW\n");
else
{
printf("\n\nThe element deleted is %d",del_element);
printf("\n\nAfter the deletion the contents of the queue are:\n");
display (queue);
}
break;
}

case 'q':
exit (0);
}
}while (ch != 'q');

getch ();
}

int insert (int cq[])
{
int info;
printf("Enter the information you want to insert: ");
scanf("%d",&info);
if (rear == size)
rear = 1;
else
rear = rear + 1;
if (front == rear)
{
flag = 1;
return;
}
cq[rear] = info;
if (front == 0)
front = 1;
return (cq[rear]);
}

int del (int cq[])
{
int info;
if (front == 0)
{
flag = 1;
return;
}
info = cq[front];
if (front == rear)
{
front = rear = 0;
return (info);
}
if (front == size)
front = 1;
else
front = front + 1;
return (info);
}

void display (int cq[])
{
int i;
for (i = front ; i <= rear ; i++)
printf("%d ",cq[i]);
}

call a page from vbscript

call a page from vbscript
=========================


Sometimes you may be in a situation where you are required to call a webpage (intranet/www) via a vbscript running locally.

Eg: Suppose you want to send email attachment via asp but want to put it in a schedular. In this call you might write the emailing logic in a asp page and make the below vbscript and put it in a local schedular.(windows schedular)


Script to be written in a vbscript

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("http://localhost/mywebpage/sendmail.asp")
set WshShell = Nothing



Alternate option is to write the logic in a oracle/ms sql server stored procedure and put it in a schedular / call the vbscript from oracle/sql server schedular.

Basic assembly language programs

Basic assembly language programs
================================


Please run the below programs using tasm.(turbo assembler)


PROGRAM 1 : PROGRAM TO FIND OUT AVERAGE OF GIVEN NUMBERS

.MODEL SMALL
.STACK 64
.DATA
NM DW 100,200,150
AVG DW ?
.CODE
BEGIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
MOV CX,3
LEA BX,NM
MOV AX,0
SUMLOP:
ADD AX,[BX]
ADD BX,2
LOOP SUMLOP
MOV CX,3
DIV CX
MOV AVG,AX
MOV AX,4C00H
INT 21H
BEGIN ENDP
END

PROGRAM 2: PROGRAM TO DEMONSTRATE UNCONDITIONAL JUMP
.MODEL SMALL
.CODE
MAIN PROC NEAR
MOV AX,01
MOV BX,01
MOV CX,03
A20 : ADD AX,01
ADD BX,AX
DEC CX
JNZ A20
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN

PROGRAM 2: PROGRAM TO DEMONSTRATE UNCONDITIONAL JUMP
.MODEL SMALL
.CODE
MAIN PROC NEAR
MOV AX,01
MOV BX,01
MOV CX,01
A20 : ADD AX,01
ADD BX,AX
SHL CX,1
JMP A20
MAIN ENDP
END MAIN


PROGRAM 3: PROGRAM TO DEMONSTRATE ECHO
.MODEL SMALL
.STACK 64
.DATA
MSG DB 'ENTER YOUR GOOD NAME :'
NM DB 22 DUP (?)
MSG1 DB 'YOUR BAD NAME IS :'
.CODE
BEGIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
MOV DX,OFFSET MSG ;LEA DX,MSG
CALL PRNT
MOV AH,3FH
MOV BX,0
MOV CX,22
LEA DX,NM
INT 21H
LEA DX,MSG1
CALL PRNT
LEA DX,NM
CALL PRNT
MOV AX,4C00H
INT 21H
BEGIN ENDP
PRNT PROC
MOV AH,40H ; SCREEN DISPLAY REQUEST PARAMETER
MOV BX,01; FILE HANDLER FOR SCREEN DISPLAY
MOV CX,22
INT 21H
RET
PRNT ENDP
END

PROGRAM 4: PROGRAM TO DEMONSTRATE ECHO
.MODEL SMALL
.STACK 64
.DATA
ID DB 50 DUP(' ')
IC DW 10H
IM DB 'ENTER STRING : ',
.CODE
BEGIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AH,40H
MOV BX,01
MOV CX,IC
LEA DX,IM
INT 21H
GETI : MOV AH,3FH
MOV BX,00
MOV CX,50
LEA DX,ID
INT 21H
MOV IC,AX

DIS : MOV AH,40H
MOV BX,01
MOV CX,IC
LEA DX,ID

CONT: INT 21H
MOV AX,4C00H
INT 21H
BEGIN ENDP
END

PROGRAM 5: PROGRAM TO DEMONSTRATE IF/ELSE
.MODEL SMALL
.STACK 64
.DATA
TXTA DB 50
TXTB DB 3
TXTC DW 1
TXTD DW 3 DUP(?)
.CODE
BEGIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
MOV CL,TXTB
MOV SI,0
MOV BX,OFFSET TXTD ; OR U CAN USE LEA BX,TXTD
LAB : MOV AL,TXTA
MUL CX
MOV [BX+SI],AX
INC SI
DEC CX
JNZ LAB
MOV AX,4C00H
INT 21H
BEGIN ENDP
END

PROGRAM 6: PROGRAM TO DEMONSTRATE THE SUM OPERATION
.MODEL SMALL
.STACK 64
.DATA
FLDC DW ?
.CODE
BEGIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX,250
ADD AX,125
MOV FLDC,AX
MOV AX,4C00H
INT 21H
BEGIN ENDP
END BEGIN


PROGRAM 7: PROGRAM TO DEMONSTRATE THE SUM OPERATION
.MODEL SMALL
.STACK 64
.DATA
FLDA DW 250
;FLDB DW 125
FLDC DW ?
.CODE
BEGIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX,FLDA
ADD AX,125
MOV FLDC,AX
MOV AX,4C00H
INT 21H
BEGIN ENDP
END BEGIN

PROGRAM 8: PROGRAM TO DEMONSTRATE MULTIPLICATION

.MODEL SMALL
.STACK 64
.DATA
MSG DB 'ENTER YOUR NUMBER :'
NM DB ?
MSG1 DB 'YOUR NUMBER X 3 IS :'
.CODE
BEGIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
MOV DX,OFFSET MSG;LEA DX,MSG
CALL PRNT
MOV AH,3FH
MOV BX,0
MOV CX,3
LEA DX,NM
INT 21H
MOV CX,8
MOV AL,0
MOV BX,3
MOV AH,NM
SUB AH,48
MULTILOOP : SHL AL,1
SHL AH,1
JNC CONT
ADDBX : ADD AX,BX
CONT : LOOP MULTILOOP

ADD AX,48
MOV NM,AL
LEA DX,MSG1
CALL PRNT
LEA DX,NM
CALL PRNT

MOV AX,4C00H
INT 21H
BEGIN ENDP

PRNT PROC
MOV AH,40H ; SCREEN DISPLAY REQUEST PARAMETER
MOV BX,01; FILE HANDLER FOR SCREEN DISPLAY
MOV CX,22
INT 21H
RET
PRNT ENDP
END

PROGRAM 9: PROGRAM TO DEMONSTRATE THE PROCEDURES
.MODEL SMALL
.STACK 64
.DATA
N1 DB 'ABCDEFGHI'
N2 DB 'JKLMNOPQR'
N3 DB 'STUVWXYZ*'
.CODE
BEGIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
CALL B10
CALL C10
MOV AX,4C00H
INT 21H
BEGIN ENDP

B10 PROC
LEA SI,N1
LEA DI,N2
MOV CX,09
B20 : MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
DEC CX
JNZ B20
RET
B10 ENDP
C10 PROC
LEA SI,N2
LEA DI,N3
MOV CX,09
C20 : MOV AL,[SI]
MOV [DI],AL
INC DI
INC SI
LOOP C20
RET
C10 ENDP
END BEGIN

access flash from javascript

access flash from javascript
======================


<object
classid="clsid:d27cdb6e-ae6d-11cf-96b8-
444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash
.cab#version=7,0,0,0"
width="400" height="550" id="flash">
<param name="allowScriptAccess"
value="sameDomain" />
<param name="movie" value="myflash.swf" />
<embed src="myflash.swf" width="400" height="550"
name="flash"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<a href="javascript:document.flash.Play();">
Play</a>
<a href="javascript:document.flash.Rewind();">
Stop</a>
<a href="javascript:document.flash.StopPlay();">
Pause</a>

just look at the following which are key methods to be called:

document.flash.Play();
document.flash.Rewind();
document.flash.StopPlay();




Also look at allowScriptAccess option at object and embed tags. This is necessary to run the movie clip.

Saturday, August 25, 2007

DIV with scroll bars

DIV with scroll bars


Make 3 divs :
* make a container div
* make 2 child within that container
* child 1 is title div
* child 2 is body div with scroll bars - overflow:auto is the key




Here is the source code

<html>

<head>
<title>Div with a scroll bar</title>
</head>

<body >

<!-- container div -->
<div style="position:absolute;overflow:hidden;top:100px;left:100px;width:300px;height:175px;border:solid black 1px;">

<!-- title div -->
<div style="position:absolute;top:0px;left:0px;width:100%;height:25px;border-bottom:solid green 5px;background-color:red;text-align:center" >Who am I?</div>
<!-- data div -->
<div style="overflow:auto;top:25px;position:absolute;left:0px;width:100%;height:150px;border-bottom:red;background-color:#cffccf;text-align:left" >
People sometimes call me mad<br/>
I am a joker<br/>
I am an honest person<br/>
I am down to earth<br/>
I am a guru<br/>
I don't have a g/f<br/>
I have very good friends<br/>
I am popular<br/>
I like challenging task<br/>
I am a software engineer<br/>

</div>

</div>

</div>

</body>

</html>


point clipping algorithm in C

point clipping algorithm in C


#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>

void initgraph1() {
int gd, gm;

gd=DETECT;
initgraph(&gd,&gm,"");
}

void main() {
int xmin, xmax, ymin, ymax;
int x[20],y[20],n,i;
clrscr();
printf("\tProgram for point clipping\n");
printf("\nEnter xmin, xmax, ymin, ymax");

scanf("\n %d", &xmin);
scanf("\n %d", &xmax);
scanf("\n %d", &ymin);
scanf("\n %d", &ymax);
printf("\n Enter no of point to be clipped");
scanf("\n %d",&n);
for(i=0;i<n;i++){
printf("Enter x for point %d :",i+1);
scanf("%d",&x[i]);
printf("\nEnter y for point %d :",i+1);
scanf("%d",&y[i]);
}

initgraph1();
/*before clipping */
outtextxy(0,0, "BEFORE CLIPPING");
rectangle(xmin, ymin, xmax, ymax);
for(i=0;i<n;i++) {
putpixel(x[i],y[i],1);
}
outtextxy(50,50, "presss a key to continue");
getch();
/*after clipping */
cleardevice();
outtextxy(0,0, "AFTER CLIPPING");
rectangle(xmin, ymin, xmax, ymax);
for(i=0;i<n;i++) {
if ((x[i] >= xmin && x[i] <=xmax) ( y[i] >=ymin && y[i] <=ymax)) {
putpixel(x[i],y[i],1);

}
else {
/*clipping */

}
}

getch();
closegraph();

}

textclip / lineclip /polygon clip program in C

textclip / lineclip/ polygon clip program in C
================= =========== =========

#include <graphics.h>
#include <conio.h>
#include <string.h>

#define MIN 100
#define MAX 300
#define STRINGS 3
#define Char_Width 8
#define Char_Height 10

void draw_basic();
void text_clipping_1 ();
void text_clipping_2 ();

struct textstring
{
int x;
int y;
char string[10];
}s[STRINGS];

void main()
{
int gd=0, gm;
initgraph ( &gd, &gm, "c:\\tc\\bgi" );
draw_basic(); text_clipping_1(); getch();
draw_basic(); text_clipping_2(); getch();
closegraph();
}
void draw_basic()
{
int i;
s[0].x=77; s[0].y=175; strcpy(s[0].string,"HELLO");
s[1].x=50; s[1].y=50; strcpy(s[1].string,"HELLO");
s[2].x=150; s[2].y=150; strcpy(s[2].string,"HELLO");
cleardevice();
rectangle(MIN,MIN,MAX,MAX);
for ( i=0; i<STRINGS; i++ )
outtextxy(s[i].x,s[i].y,s[i].string);
getch();
}
void text_clipping_1 ()
{
int i, length;
cleardevice();
rectangle(MIN,MIN,MAX,MAX);
for ( i=0; i<STRINGS; i++ )
{ if ( (s[i].y<MIN) (s[i].y>MAX) )
continue;
length = strlen(s[i].string) * Char_Width;
if ( (s[i].x<MIN) (s[i].x>MAX) )
continue;
outtextxy(s[i].x,s[i].y,s[i].string);
}
outtextxy(10,10,"Clipping 1");
}
void text_clipping_2 ()
{
int i, length;
cleardevice();
rectangle(MIN,MIN,MAX,MAX);
for ( i=0; i<STRINGS; i++ )
{ if ( (s[i].y<MIN) (s[i].y>MAX) )
continue;
length = strlen(s[i].string) * Char_Width;
if ( (s[i].x+length<MIN) (s[i].x>MAX) )
continue;
if ( (s[i].x+length>MIN) && (s[i].x<MIN) )
{ int words,ii,jj;
char newstring[10];
words = ( MIN - s[i].x ) / Char_Width;
for ( ii=(strlen(s[i].string)-words),jj=0; ii<=strlen(s[i].string); ii++)
newstring[jj++] = s[i].string[ii];
newstring[jj] = '\0';
outtextxy(MIN+1,s[i].y,newstring);
continue;
}
outtextxy(s[i].x,s[i].y,s[i].string);
}
outtextxy(10,10,"Clipping 2");
}


lineclip
======



#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <process.h>
#include <math.h>
#define ML 5
int Xmin,Xmax,Ymin,Ymax, ii[4][2]={0};
int l[5][4]={ {10,150,175,200},
{225,50,250,200},
{500,400,200,175},
{150,150,250,250},
{10,400,475,180}};
void dr();
void dl();
void cs();
void drawcsline(int, int, int, int, int);
void main()
{
int gd=0, gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
dr(); getch();
dl(); getch();
cs(); getch();
closegraph();
}
void dr()
{ Xmin = 100; Xmax = 400; Ymin = 100; Ymax = 300;
rectangle(Xmin,Ymin,Xmax,Ymax);
}
void dl()
{ int i;
for(i=0; i<ML; i++)
line(l[i][0],l[i][1],l[i][2],l[i][3]);
}
void cs()
{ int i, j, x1, y1, x2, y2;
for(i=0; i<ML; i++)
{
x1=l[i][0]; y1=l[i][1]; x2=l[i][2]; y2=l[i][3];
drawcsline(x1,y1,x2,y2,i);
}
cleardevice(); dr(); dl(); getch();
}
void drawcsline(int x1, int y1, int x2, int y2, int iii)
{ int pt1, pt2, k, finalx, finaly, minx, miny, maxx, maxy, checkxy(int, int);
void setintersection(int, int, int, int);
minx = ( x1 > x2 ) ? x2 : x1;
miny = ( y1 > y2 ) ? y2 : y1;
maxx = ( x1 > x2 ) ? x1 : x2;
maxy = ( y1 > y2 ) ? y1 : y2;
pt1 = checkxy(x1,y1);
pt2 = checkxy(x2,y2);
if ( pt1 == 0 && pt2 == 0 ) //both inside
return;
if ( pt1 == 0 && pt2 != 0 ) //only pt1 inside
{ setintersection(x1,y1,x2,y2);
for ( int k=0; k<4; k++)
{ finalx = ii[k][0];
finaly = ii[k][1];
if ( ( finalx > minx && finalx < maxx ) && ( finaly > miny && finaly < maxy ) )
break;
else
continue;
}
l[iii][2] = finalx;
l[iii][3] = finaly;
}
if ( pt1 != 0 && pt2 == 0 ) //only pt2 inside
{ setintersection(x1,y1,x2,y2);
for ( int k=0; k<4; k++)
{ finalx = ii[k][0];
finaly = ii[k][1];
if ( ( finalx > minx && finalx < maxx ) && ( finaly > miny && finaly < maxy ) )
break;
else
continue;
}
l[iii][0] = finalx;
l[iii][1] = finaly;
}
if ( pt1 != 0 && pt2 != 0 ) //both outside
{ setintersection(x1,y1,x2,y2);
for ( k=0; k<4; k++)
{ finalx = ii[k][0];
finaly = ii[k][1];
if ( ( finalx > minx && finalx < maxx ) && ( finaly > miny && finaly < maxy ) )
break;
else
continue;
}
l[iii][0] = finalx;
l[iii][1] = finaly;
for ( k=0; k<4; k++)
{ finalx = ii[k][0];
finaly = ii[k][1];
if ( ( finalx > Xmin && finalx < Xmax ) && ( finaly > Ymin && finaly < Ymax ) )
if ( ( finalx > minx && finalx < maxx ) && ( finaly > miny && finaly < maxy ) )
if ( finalx != l[iii][0] &&amp;amp; finaly != l[iii][1] )
break;
else
continue;
}
l[iii][2] = finalx;
l[iii][3] = finaly;

}
}
void setintersection(int x1, int y1, int x2, int y2)
{ int xxmin = 100, yymin = 100, xxmax = 400, yymax = 300;
float slope = (y2-y1)* 1.0 / (x2-x1);
ii[0][0] = x1 + ( yymin - y1 ) / slope;
ii[0][1] = yymin;
ii[1][0] = x1 + ( yymax - y1 ) / slope;
ii[1][1] = yymax;
ii[2][0] = xxmin;
ii[2][1] = y1 + slope * ( xxmin - x1 );
ii[3][0] = xxmax;
ii[3][1] = y1 + slope * ( xxmax - x1 );
}
int checkxy(int x, int y)
{ /* Check where x1,y1 lies Above Below Right Left
1 0 0 1
1001 1000 1010
--------------------
0001 0000 0010
-------------------
0101 0100 0110 */
int a,b,r,l;
a = ( y < Ymin ) ? 1 : 0;
b = ( y > Ymax ) ? 1 : 0;
r = ( x > Xmax ) ? 1 : 0;
l = ( x < Xmin ) ? 1 : 0;
return ( a*1000 + b*100 + r*10 + l );
}


Polygon Slip

//polygon clipping...
#include <graphics.h>
#include <conio.h>
#include <string.h>

int minx, miny, maxx, maxy;

int mypoly[22] = {200,50,250,100,300,100,250,150,250,200,200,150,
150,200,150,150,100,100,150,100,200,50};
int newpoly[50];
int cutx, cuty;

void clippoly(int, int []);
void set_intersection(char *, int, int, int, int);

void main()
{
int gd=0, gm;
initgraph (&gd, &gm,"c:\\tc\\bgi");

minx = 125; miny = 75; maxx=275; maxy=175;

rectangle(minx, miny, maxx, maxy);
getch();
drawpoly(11,mypoly);
getch();

clippoly(11, mypoly);
getch();

closegraph();
}

void clippoly(int edges, int mypoly[])
{
int temppoly[40];
int i, counter=0;
for (i=0; i<edges*2; i+=2)
{
// left clip...
if ( mypoly[i] > minx )
{
temppoly[counter++] = mypoly[i];
temppoly[counter++] = mypoly[i+1];
}
else
{
if ( i==0 )
{
set_intersection("left",mypoly[i],mypoly[i+1],mypoly[edges*2-4],mypoly[edges*2-3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
set_intersection("left",mypoly[i],mypoly[i+1],mypoly[i+2],mypoly[i+3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
}
else
{
set_intersection("left",mypoly[i-2],mypoly[i-1],mypoly[i],mypoly[i+1]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
set_intersection("left",mypoly[i],mypoly[i+1],mypoly[i+2],mypoly[i+3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
}
}
}
edges = counter/2;
counter = 0;
for (i=0; i<edges*2; i+=2)
{
// right clip...
if ( temppoly[i] < maxx )
{
newpoly[counter++] = temppoly[i];
newpoly[counter++] = temppoly[i+1];
}
else
{
if ( i==0 )
{
set_intersection("right",temppoly[i],temppoly[i+1],temppoly[edges*2-4],temppoly[edges*2-3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
set_intersection("right",temppoly[i],temppoly[i+1],temppoly[i+2],temppoly[i+3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
}
else
{
set_intersection("right",temppoly[i-2],temppoly[i-1],temppoly[i],temppoly[i+1]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
set_intersection("right",temppoly[i],temppoly[i+1],temppoly[i+2],temppoly[i+3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
}
}
}
edges = counter/2;
counter = 0;
for (i=0; i<edges*2; i+=2)
{
// bottom clip...
if ( newpoly[i+1] < maxy )
{
temppoly[counter++] = newpoly[i];
temppoly[counter++] = newpoly[i+1];
}
else
{
if ( i==0 )
{
set_intersection("bottom",newpoly[i],newpoly[i+1],newpoly[edges*2-4],newpoly[edges*2-3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
set_intersection("bottom",newpoly[i],newpoly[i+1],newpoly[i+2],newpoly[i+3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
}
else
{
set_intersection("bottom",newpoly[i-2],newpoly[i-1],newpoly[i],newpoly[i+1]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
set_intersection("bottom",newpoly[i],newpoly[i+1],newpoly[i+2],newpoly[i+3]);
temppoly[counter++] = cutx;
temppoly[counter++] = cuty;
}
}
}
edges = counter/2;
counter = 0;
for (i=0; i<edges*2; i+=2)
{
// top clip...
if ( temppoly[i+1] > miny )
{
newpoly[counter++] = temppoly[i];
newpoly[counter++] = temppoly[i+1];
}
else
{
if ( i==0 )
{
set_intersection("top",temppoly[i],temppoly[i+1],temppoly[edges*2-4],temppoly[edges*2-3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
set_intersection("top",temppoly[i],temppoly[i+1],temppoly[i+2],temppoly[i+3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
}
else
{
set_intersection("top",temppoly[i-2],temppoly[i-1],temppoly[i],temppoly[i+1]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
set_intersection("top",temppoly[i],temppoly[i+1],temppoly[i+2],temppoly[i+3]);
newpoly[counter++] = cutx;
newpoly[counter++] = cuty;
}
}
}
cleardevice();
rectangle(minx, miny, maxx, maxy);
setcolor(2);
drawpoly(counter/2, newpoly);
setcolor(15);
getch();
drawpoly(11,mypoly);
}

void set_intersection(char * clipside, int x1, int y1, int x2, int y2)
{
float slope;
if ( x1 != x2 )
slope = (y2-y1)*1.0/(x2-x1);

if ( strcmp(clipside,"left")==0 )
{ cutx = minx; cuty = y1 + slope * ( minx - x1 ); }
if ( strcmp(clipside,"right")==0 )
{ cutx = maxx; cuty = y1 + slope * ( maxx - x1 ); }
if ( strcmp(clipside,"bottom")==0 )
{
if ( x1 != x2 )
cutx = x1 + ( maxy - y1 ) / slope;
else
cutx = x1;
cuty = maxy;
}
if ( strcmp(clipside,"top")==0 )
{
if ( x1 != x2 )
cutx = x1 + ( miny - y1 ) / slope;
else
cutx = x1;
cuty = miny;
}
}

Transformation, Rotation and Scaling in C - computer graphics algorithm

/* Graphics program for the different types of transformations such as
1.Translation
2.Rotation
3.Scaling */


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>

double finmat[3][3];
double identity[3][3];
int origmat[3][3]={{320,190,1},
{370,290,1},
{270,290,1}};
int transform[3][3];
int drawmat[8];

void multiply();
void setfin();
void transmat();

void main()
{
int gd=DETECT,gm,ch,x,y,i,j,k,errorcode,refx=320,refy=240;
double thita;
double costhita,sinthita;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(RED);
do
{
drawmat[0] = origmat[0][0];
drawmat[1] = origmat[0][1]; //drawing triangle
drawmat[2] = origmat[1][0];
drawmat[3] = origmat[1][1];
drawmat[4] = origmat[2][0];
drawmat[5] = origmat[2][1];
drawmat[6] = origmat[0][0]; // connecting
drawmat[7] = origmat[0][1]; // to first
transmat();

drawpoly(4,drawmat);
printf("\n");
printf("1.To Translate an Object\n");
printf("2.To Rotate an Object\n");
printf("3.To Scale an Object\n");
printf("4.To Terminate the Program\n");
printf("Enter Your Choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter Translation Value For x : ");
scanf("%d",&x);
printf("Enter Translation Value For y : ");
scanf("%d",&y);
identity[0][0] = 1;
identity[0][1] = 0;
identity[0][2] = x; // 1 0 x
identity[1][0] = 0; // 0 1 y
identity[1][1] = 1; // 0 0 1
identity[1][2] = y;

identity[2][0] = 0;
identity[2][1] = 0;
identity[2][2] = 1;
multiply();
setfin();
getch();
clrscr();
cleardevice();
break;
case 2:
printf("Enter The Rotation Parameter 0: ");
scanf("%lf",&thita);
costhita = cos(thita*3.1428/180);
sinthita = sin(thita*3.1428/180);
//refx=320 refy=240
identity[0][0] = costhita;
identity[0][1] = -sinthita;
identity[0][2] = refx * ( 1 - costhita ) + refy * sinthita;
identity[1][0] = sinthita;
identity[1][1] = costhita;

identity[1][2] = refy * ( 1 - costhita ) - refx * sinthita;
identity[2][0] = 0;
identity[2][1] = 0;
identity[2][2] = 1;
multiply();
setfin();
getch();
clrscr();
cleardevice();
break;
case 3:
printf("Enter Scaling Value For x : ");
scanf("%d",&x);
printf("Enter Scaling Value For y : ");
scanf("%d",&y);
identity[0][0] = x;
identity[0][1] = 0;
identity[0][2] = ( 1 - x ) * refx;
identity[1][0] = 0;
identity[1][1] = y;

identity[1][2] = ( 1 - y ) * refy;
identity[2][0] = 0;
identity[2][1] = 0;
identity[2][2] = 1;
multiply();
setfin();
getch();
clrscr();
cleardevice();
break;
case 4:
getch();
cleardevice();
closegraph();
restorecrtmode();
exit(0);
default:
printf("Select your choice!\n");
getch();
break;
}
}while(ch!=4);
}

void multiply()
{
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
finmat[i][j]=0;
for(k=0;k<3;k++)
{
finmat[i][j] += identity[i][k] * transform[k][j];
}
}
}
}
void setfin()
{
drawmat[0] = int(finmat[0][0]);
drawmat[1] = int(finmat[1][0]);
drawmat[2] = int(finmat[0][1]); // 2x3
drawmat[3] = int(finmat[1][1]); // 0,0 0,1 0,2
drawmat[4] = int(finmat[0][2]); // 1,0 1,1 1,2
drawmat[5] = int(finmat[1][2]);
drawmat[6] = int(finmat[0][0]);
drawmat[7] = int(finmat[1][0]);
drawpoly(4,drawmat);
}
void transmat()
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
transform[j][i] = origmat[i][j];
}