List of all C\C++ programs

October 3, 2009
  1. Search an integer from an array of integers in C
  2. Write a program for copying content of one file to another in C
  3. Write a program to implement Stack in C
  4. Write a program for Implement Interrupt Procedure in C

Search an integer from an array of integers in C

October 3, 2009

/* Click here to see a list of all C/C++ programs */

#include<stdio.h>

main()
{
int array[10];
int i,found,element,position;
found=0;   //variable ‘found’ acts like a flag variable

printf(“\nPlease enter 10 integer elements : \n\n”);
for(i=0;i<10;i++)   //to accept 10 integers in the array
{
printf(“Element %d: “,i+1);
scanf(“%d”,&array[i]);
}

printf(“\nPlease enter the element to be searched: “);
scanf(“%d”,&element);

for(i=0;i<10;i++)
{
if(array[i]==element)
{
found=1;   //if the element is present, assign found=1
position=i+1;   //store the position at which the element is present
}
}

if(found==1)   //if found has value ’1′, the element must be present
{
printf(“\nThe element %d is present at position %d\n\n”,element,position);
}
else   //if  found still has original value ’0′, then the element is not present
{
printf(“\nThe element %d is not present in the array\n\n”,element);
}
}

/* OUTPUT:

[tc@localhost ~]$ cd Desktop
[tc@localhost Desktop]$ gcc searcharray.c
[tc@localhost Desktop]$ ./a.out

Please enter 10 integer elements :

Element 1: 12
Element 2: 5
Element 3: 63
Element 4: 41
Element 5: 74
Element 6: 91
Element 7: 87
Element 8: 324
Element 9: 86
Element 10: 59

Please enter the element to be searched: 86

The element 86 is present at position 9

[tc@localhost Desktop]$ ./a.out

Please enter 10 integer elements :

Element 1: 12
Element 2: 5
Element 3: 63
Element 4: 41
Element 5: 74
Element 6: 91
Element 7: 87
Element 8: 324
Element 9: 86
Element 10: 59

Please enter the element to be searched: 22

The element 22 is not present in the array

[tc@localhost Desktop]$

*/

/* Click here to see a list of all C/C++ programs */


Life just gets More Audible with AUDACITY

October 2, 2009

/* Click here to see the entire list. */


One of my favourite software that I cannot ignore .

AUDACITY is a really cool software especially for those who want to record their voices , instruments etc and don’t want the hassle of sopphisticated audio editing software packages.

As a musicain I have recorded loads of  melody using audacity.

The best advantages.

  1. It is very simple and has avery short learning curve.
  2. Its a cross platfrom software, (works in Windows, Linux ,MAC etc)
  3. Its an  open source and its free.
  4. It has a numbe of effects(Like wahwah etc).
  5. The recording can be expoted as mp3 file.
  6. This is a screenshot of  the effectsSo if you want to compose music by yourself you can compose it in layes. First recording the tempo, then the rythm the solo vocal or addition parts. (For example check out : RoyRock.mp3)One can even import audio  and edit and add effects to it.

Screenshot-1

Some cool effects

All thats left to say is.

AUDACITY!!!AUDACITY!!!AUDACITY!!!

For more screenshots click HERE

Click here to Dowload : Audacity

HopeThisHelps

/* Click here to see the entire list. */


5. XML and JavaScript (contd..)

October 2, 2009

/* Click here to see a list of all XML tutorials */

Now let us wirte a more complex XML and display it  using JavaScript.
(Newbies read : Writing XML and/or   Displaying XML using JavaScript )

This is  a Sales OrderXML for a company

Salesorder.xml
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<ORDER>
<SALESORDER>
<NUMBER>01</NUMBER>
<DATE>27TH SEPT 2009</DATE>
<CUSTOMER>
<CNO>922</CNO>
<NAME>JIM CORBETT</NAME>
<STREET>JUNNER</STREET>
<CITY>PUNE</CITY>
<ZIP>409012</ZIP>
</CUSTOMER>
<ITEMS>
<PARTNO>A63</PARTNO>
<DESCRIPTION>A LONG LASTING KEROSENE LAMP 1963</DESCRIPTION>
<QUANTITY>10 DZN</QUANTITY>
<PRICE>960 PAISE</PRICE>

</ITEMS>
</SALESORDER>
<SALESORDER>
<NUMBER>02</NUMBER>
<DATE>27TH SEPT 2009</DATE>
<CUSTOMER>
<CNO>981</CNO>
<NAME>BEAR GRYLLS</NAME>
<STREET>K-WADI</STREET>
<CITY>PUNE</CITY>
<ZIP>501302</ZIP>
</CUSTOMER>
<ITEMS>
<PARTNO>A69</PARTNO>
<DESCRIPTION>PACKAGE- A FLINT, A WATER BOTTLE AND A HUNTING KNIFE</DESCRIPTION>
<QUANTITY>2 DZN</QUANTITY>
<PRICE>RS 7000</PRICE>
</ITEMS>
</SALESORDER>
</ORDER>

Salesorder.html

<html>
<body>
<script type=”text/javascript”>
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument(“”,”",null);
}
else
{
alert(‘Your browser cannot handle this script’);
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load(“SalesOrder.xml”);
var x=xmlDoc.getElementsByTagName(“SALESORDER”);

document.write(“<table border=’1′>”);
document.write(“<thead>”);
document.write(“<tr><th ROWSPAN=’2′>ORDER NO</th><th ROWSPAN=’2′>DATE</th><th  COLSPAN=’3′>CUSTOMER</th><th COLSPAN=’3′>ITEMS PUSCHASED</th></tr>”);
document.write(“<tr><th>CNo</th><th >Name</th><th >Address</th><th>PartNo</th><th>Quantity</th><th >Price</th></tr>”);
document.write(“</thead>”);
//document.write(“<tr>
//document.write(“<td>CNo</td><td >Name</td><td>Address</td><td>PartNo</td><td>Quantity</td><td >Price</td>”);
//document.write(“</tr>”);
document.write(“<tfoot>”);
document.write(“<tr><th colspan=’9′>SALER ORDER  FOR THE FUTURE_PIONEERS_OF_INDIA 2009</th></tr>”);
document.write(“</tfoot>”);

for (var i=0;i<x.length;i++)
{
document.write(“<tr>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“NUMBER”)[0].childNodes[0].nodeValue);
document.write(“</td>”);

document.write(“<td>”);
document.write(x[i].getElementsByTagName(“DATE”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“CUSTOMER”)[0].getElementsByTagName(“CNO”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“CUSTOMER”)[0].getElementsByTagName(“NAME”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“CUSTOMER”)[0].getElementsByTagName(“STREET”)[0].childNodes[0].nodeValue );
document.write(“,”);
document.write(x[i].getElementsByTagName(“CUSTOMER”)[0].getElementsByTagName(“CITY”)[0].childNodes[0].nodeValue);
document.write(“-”);
document.write(x[i].getElementsByTagName(“CUSTOMER”)[0].getElementsByTagName(“ZIP”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“ITEMS”)[0].getElementsByTagName(“PARTNO”)[0].childNodes[0].nodeValue);
document.write(“-</BR>”);
document.write(x[i].getElementsByTagName(“ITEMS”)[0].getElementsByTagName(“DESCRIPTION”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“ITEMS”)[0].getElementsByTagName(“QUANTITY”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);
document.write(x[i].getElementsByTagName(“ITEMS”)[0].getElementsByTagName(“PRICE”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“</tr>”);
}
document.write(“</table>”);
}
</script>

</body>
</html>

Output
XML

Hopethishelps
/* Click here to see a list of all XML tutorials */


4.Displaying XML using javascript

October 2, 2009

/* Click here to see a list of all XML tutorials */

A number of porgramming and scripting languages like VB.net javascript etc have the ability to read  XML.

While reading an XML files using javascript, one must remeber which browser it is to be displayed in. Different browsers read XML in different ways.
For eg   IE explorer uses the ActiceXObject    while      Firefox,Opera on the other hand uses  document.implementation.createDocument method.
If you are not sure  which browser will be used, then use both methods.

Now for the company .xml

company.xml

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<company>
<employee>
<name>Jack</name>
<post>Manager</post>
<employee>
<company>
<employee>
<name>John</name>
<post>CEO</post>
<employee>
</company>

so open notepad(or any other text editor):

<!– @page { margin: 2cm } P { margin-bottom: 0.21cm } –>

company.html
<!– @page { margin: 2cm } P { margin-bottom: 0.21cm } –> <!– @page { margin: 2cm } P { margin-bottom: 0.21cm } –><html>
<body>
<script type=”text/javascript”>    //usual javascript syntax
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument(“”,”",null);
}
else
{
alert(‘Your browser cannot handle this script’);
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load(“SalesOrder.xml”);
var x=xmlDoc.getElementsByTagName(“SALESORDER”);

//The information is to be displayed in a table form so we start writing the HTML table code using javascript

document.write(“<table border=’1′>”);
document.write(“<thead>”);
document.write(“<tr><th >Empolyee Name</th><th >Post</th></tr>”);//writing the table headers

var x=xmlDoc.getElementsByTagName(“company”); //creating a variable x which gets all elements having company tag

for (var i=0;i<x.length;i++)
{
document.write(“<tr>”); //start row
document.write(“<td>”);

//  To get employeename ,we first must go to employee then look inside for name tag       so,    x[i] (company)–>employee–> name
document.write(x[i].getElementsByTagName(“employee”)[0].getElementsByTagName(“name”)[0].childNodes[0].nodeValue);
document.write(“</td>”);

document.write(“<td>”);
document.write(x[i].getElementsByTagName(“DATE”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“<td>”);

document.write(“</tr>”);//end row

}

</script>

</body>
</html>

for more information visit : w3schools.com

Hope this help
Roy

document.implementation.createDocumen

/* Click here to see a list of all XML tutorials */


3.XML Schema

October 1, 2009

/* Click here to see a list of all XML tutorials */

Once again,XML is only used to DESCRIBE DATA.

Hence we need to understand two more components while learning about XML:

  1. XML DTD
  2. XML SCHEMA

these are used for defining the XML Structure

XML schema
This tutorial will Just give you an short and sweet understanding for more detailed Info see: w3schools

let us create a schema for the company example:

<!–Step1.–>
<!– first we specify the version–>
<?xml version=”1.0″?>
<!– now we must create an alias for the schema say  ‘xsd’ is the alias for this schema , thus we define –>
<xsd:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”><!– xlmns stands for namespace –>

<!–Step2. Defining the structure –>
<!–since every element belongs to the ‘xsd’ schema , we will use  xsd  tag before specifying the element–>
<xsd : element  name=”company”>

<xsd : element name =”employee”><!–   Notice that employee has more than one subelement under it, hence it is complex>
<xsd: complexType><!–      used when  the element defined has subelements : here employee has tow sub elements under it- name and post>
<xsd: sequence><!–         specify sequence in which hte elements are supposed to be placed–>

<xsd:element name=”name” type=”xsd:string”/><!–these are simple elements with values so we also specify the type of values they hold–>
<xsd:element name=”Post” type=”xsd:string”/>

</xsd:sequennce>
</xsd:complexType>
</xsd:element>
</xsd:element>
</xsd:schema><!–closing the root element–>

Hence we get :
company.xsd(save as .xsd )

<?xml version=”1.0″?>

<xsd:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
<xsd : element  name=”company”>
<xsd : element name =”employee”>
<xsd: complexType><xsd: sequence>
<xsd:element name=”name” type=”xsd:string”/>
<xsd:element name=”Post” type=”xsd:string”/>
</xsd:sequennce>
</xsd:complexType>
</xsd:element>
</xsd:element>
</xsd:schema>

company.xml

<?xml version=”1.0″?>

<company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="company.xsd">
 <employee>
 <name>Jack</name>
 <post>Manager</post>
 <employee>
<employee>
 <name>John</name>
 <post>CEO</post>
 <employee>
 </company>
Hope This has been of some use,

/* Click here to see a list of all XML tutorials */


2.The realistic Funtastic Virtual Box

October 1, 2009

/* Click here to see the entire list. */

we’ll a lot of people are becoming familiar with software that virtually emulate hardware. Like vitrual CD ROMS etc

Now lets suppose you’ve heard a new OS(Operating system)  and would like to give it a try, but at the same time you  are not sure  if installing it would be the right idea.Then Virtual Box is for you.

For those who have not heard of this concept before

Virtual Box and other System emulators provide a method of installing Operating system  witthout affecting the system.
For example, I am currently running XP from a very ,very………long time , now i have found that Linux mint is as good. However I have very little knowledge of linux, so before taking a direct leap into the unknown.  I’d like to test it and learn more about it. So I can install it on a Virtual Box

Are there other emulators like Virtual Box ?
Yes. infact there are. Currently many people many people are using  VMware. It a pretty good software itself but  It not free(though the VMplayer is free, but does not contain much features and cannot create a VM ).  Virtual Box on the other hand is a freeware by Sun Microsystems . A host of operating system can be installed on it like Windows(XP ,Vista), Linux,MAC,Solaris etc.

Virtual Box(To Download click here and download for your currrent OS)
It starts quickly. Multiple OS can be installed.Has some really good features:

  1. VBox guest Addition – similar to vmware tools , once installed you can easily switch between Host OS(you main system OS) and guest OS(you virtual OS).The guestaddition is a must install after the OS is installed.
  2. Seamless window- one really cool feature that helsp you work on both your real system OS(Host OS) as well as Virtual system OS(guestOS).Check out this screen shot  to get an idea.

Seamless Windows
Note: the window frames in black belong to Linux, the ones in blue belong to Winows XP. also notice the two bars at the bottom of the screen.
Here I have installed Linux Mint  On XP to test it before installing it as my real OS.

There are a lot more features to explore.

For more idea abbout the VBox  check out the End-user manual at virtualBox.org :To Click here

Hope it helps

/* Click here to see the entire list. */

DidYouKnow???
What is the most intriguing data center?
Google, of course.  Located in Dalles, Oregon, on the banks of the Columbia River, 80 miles east of Portland, they house an estimated 500,000 around the world, spread across 25 locations, that stores and estimated 200 petabytes.  Also hydroelectric dam is used to power two four-story cooling towers.
antonperez.com


Follow

Get every new post delivered to your Inbox.