Tuesday, June 26, 2012

File Input and Output in C -- Character Read and Write

#include


#include

char data,ch='a';

void main()

{ clrscr();

FILE *ptr;

ptr=fopen("file1.txt","a");



while(ch!='!')

{

printf("Enter any Character");

scanf("%c",&data);

ch=data;

fputc(data,ptr);

}

fclose(ptr);

}


//Reading From File

#include


#include

char data;

void main()

{ clrscr();

FILE *ptr;

ptr=fopen("file1.txt","r");



while((data=fgetc(ptr))!=EOF)

{

printf("%c",data);

}

fclose(ptr);

}

Tuesday, September 6, 2011

Changing Theme At RunTime


 private void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["thm"]== "T12")
            Page.Theme = "T12";
        else if (Request.QueryString["thm"] == "T14")
            Page.Theme = "T14";
        else
            Page.Theme = "T16";

    }

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddl.SelectedIndex == 0)
        {
            Response.Redirect("Default.aspx?thm=T12");
        }

        if (ddl.SelectedIndex == 1)
        {
            Response.Redirect("Default.aspx?thm=T14");
        }

        if (ddl.SelectedIndex == 2)
        {
            Response.Redirect("Default.aspx?thm=T16");
        }


    }

Wednesday, June 15, 2011

Variable and Constant Naming Rules

The following rules should be remembered while naming variables or constants:
  1. It must begin with an alphabet or an underscore (_). 
  2. It must only contain alphabets, numbers, and underscores.
  3. Maximum length of variable or a constant name is 1023 characters.
  4. Variable or Constant name must not contain any keywords or special symbols. 
  5. Variable or Constant names are case-insensitive. This means ABC and abc are same. However, the common language runtime (CLR) uses case-sensitive binding. Therefore, when you produce an assembly or a DLL and make it available to other assemblies, your names are no longer case-insensitive. For example, if you define a class with a variable| constant called ABC, and other assemblies make use of your class through the common language runtime, they must refer to the element as ABC. If you subsequently recompile your class and change the element's name to abc, the other assemblies using your class could no longer access that element. Therefore, when you release an updated version of an assembly, you should not change the alphabetic case of any public variables|constant.


Constants in VB.NET

Definition: Constant is a memory location to store data / value. It store one value at a time.


Property: The main property of a constant is that the value stored in it donot changes throughout the program execution.

Declaring Constants:

Const statement is used to declare and allocate memory for one or more variables.  The syntax of declaring variable using Const statement is
[{ Public | Protected | Friend | Protected Friend | Private }]  [Shadows] Const constantname [As datatype] [= expression | initialvalue]

~ Parts of Const Statement ~
  • Public: The constant declared as Public means that you can access data anywhere without any restrictions.
  • Protected: Suppose a constant is declare inside the class and you do not want it to be access outside the class then protected access specifier allows you to declare a constant that is only accessible in the class where it is declared and its derived class. 
  • Protected Friend:
  • Private: Private access specifier allows you to declare a constant that is only accesible in the class where it is declared. You cannot access the Private constant outside the class.
  • Shadows: 
  • constantname: A user defined name of a constant. Multiple constant names must be separated by commas. 
  • datatype: Specifies the type of data stored in a constant. If you do not specify the datatype, the constant takes the datatype of expression | initialvalue.  If you do not specify datatype and expression, the datatype is set to Object. 
  • expression | initialvalue: Used to initialize a constant. in case of expression , the result is assigned as inital value.

Variables in VB.NET

Definition: Variable is a memory location to store data / value. It store one value at a time.

Property: The main property of a variable is that the value stored in it changes throughout the program execution.

Declaring Variables

Dim statement is used to declare and allocate memory for one or more variables.  The syntax of declaring variable using Dim statement is

[{ Public | Protected | Friend | Protected Friend | Private | Static}] [Shared] [Shadows] [ReadOnly] Dim [WithEvents] variablename[(boundlist)] [As [New] datatype] [= expression | initialvalue]

~ Parts of Dim Statement ~
  • Public: The variable declared as Public means that you can access data anywhere without any restrictions.
  • Protected: Suppose a variable is declare inside the class and you do not want it to be access outside the class then protected access specifier allows you to declare a variable that is only accessible in the class where it is declared and its derived class. 
  • Protected Friend:
  • Private: Private access specifier allows you to declare a variable that is only accesible in the class where it is declared. You cannot access the Private variable outside the class.
  • Static: When the procedure or function ends then it automatically releases the memory allocated to local variables. As a result, the value stored in a local variables is also lost. If you want to retain the value of local variables after procedure or function ends than that variable must be declared as Static. 
  • Shared: Every instance of a class keeps its own copy of variable (separate memory allocation and store different values). When a variable is declared as Shared, all instances access the same memory location and is available to every instance of class. If one instance changes value of a shared variable, all other instances access the new updated value. 
  • Shadows: 
  • ReadOnly: It means you can only read the value of a variable. It is not possible to write anything.
  • WithEvents: It means that variable can respond to an event.
  • variablename: A user defined name of a variable. Multiple variable names must be separated by commas and the datatype of all the variables is given in the first As clause. 
  • boundlist: It is used to declare arrays.  An array can have upto 60 dimensions.
  • New: Creates a new instance of the class when statement executes.
  • datatype: Specifies the type of data stored in a variable. If you do not specify the datatype, the variable takes the datatype of expression | initialvalue.  If you do not specify datatype and expression, the datatype is set to Object. 
  • expression | initialvalue: Used to initialize a variable. in case of expression , the result is assigned as inital value.

Sunday, October 10, 2010

Singly Linked List - Insertion At Front

//SINGLY LINKED LIST - Insertion At Front
#include < stdio.h >
#include< conio.h >

struct node
{
int info;
struct node *link;
}       ;

*start=NULL, *last=NULL;

int x;
char ch='y';

void display()
{
//TRAVERSAL
struct node *p;
p=start;
printf("\n LIST IS \n");
do
{
    printf("|%d|%X| --- >",p- >info, p- >link);
    p=p- >link;
} while (p->link!=NULL);
    printf("| %d | %X |",p- >info, p- >link);
}

//Function To Insert Node At Front
void atfront()
{
//dynamically allocate memory
struct node *new1;

      clrscr();

do
{
    printf("\n\n Enter Element ");
    scanf("%d",&x);
    //create new node
    new1=(struct node*) malloc(sizeof(new1));

    new1- >info=x;
    new1- >link=NULL;

    if (start==NULL)
    { printf("first node added\n\n");
      start=new1;
      last=new1;
    }
    else
    {
       new1- >link=start;
       start=new1;
    }
    printf("\n\nDo you want to contnue");
    ch=getch();
}  while (ch=='y') ;

printf("/n/nAddress of first  node :%X ",start);
printf("/n/nAddress of last node :%X \n\n\n",last);
}

void main()
{
//Call InsertionAtFront Function
atfront();
//Print List
display();
}

Saturday, May 29, 2010

Queue - Deletion Operation

#include< stdio.h >
#include< conio.h >
//global declaration
int a[20],n,i,rear,front,x;

void main()
{ clrscr();
printf("Enter Total Number of Elements = ");
scanf("%d",&n);
//initialise
rear=0;
front=0;
//insert element
while(rear < n)
{       //check for Overflow
    if(rear > n)
    {
        printf("\nQueue Full");
        exit();
    }
    else
    {
        //enter element
        printf("\nEnter Element a[%d] = ",rear);
        scanf("%d",&x);
        a[rear]=x;
        //reset rear
        rear=rear+1;
    }
}


//Traverse Stack
printf("\n***** Elements of Queue Are ***** \n");
while(i < rear)
{
    printf("_____\n");
    printf("| %d |\n",a[i]);
    i=i+1;
}
printf("_____\n");
getch();



//Delete Element of Queue
while(front < n)
{


    printf("\nElement Deleted from stack a[%d] = %d ",front,a[front]);
    //reset front
    front=front+1;

}
    printf("\nQueue Empty");
    getch();
}