June 21, 2015

C program to Read From a File

#include <stdio.h>
#include <stdlib.h>
void main()
{
    FILE *fptr;
    char filename[15];
    char ch;
    printf("Enter the filename to be opened \n");
    scanf("%s", filename);
    /*  open the file for reading */
    fptr = fopen(filename, "r");
    if (fptr == NULL)
    {
        printf("Cannot open file \n");
        exit(0);
    }
    ch = fgetc(fptr);
    while (ch != EOF)
    {
        printf ("%c", ch);
        ch = fgetc(fptr);
    }
    fclose(fptr);
}

C Program to create and write a File

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

int main()
{
FILE *fp;
char ch;
fp = fopen("one.txt", "w");
printf("Enter data");
while( (ch = getchar()) != EOF) {
    putc(ch,fp);
}
fclose(fp);

return 0;
}

Programming Manual

 

Star Formations http://cs-study.blogspot.com/2013/10/c-program-to-print-different-star.html
Hollow Square http://cs-study.blogspot.com/2013/10/c-program-to-print-hollow-stars-square.html
Ascending Order without loops http://cs-study.blogspot.com/2013/10/c-program-to-display-integers-in.html 
Phases of a Program  http://cs-study.blogspot.com/2013/09/c-program-phases-writing-and-executing.html
Dev C++ Installation  http://cs-study.blogspot.com/2013/09/installation-of-dev-c.html
Programming Introduction  http://cs-study.blogspot.com/2013/09/introduction-to-programming.html
Bubble Sort  http://cs-study.blogspot.com/2012/12/bubble-sort.html
Binary Search  http://cs-study.blogspot.com/2012/12/binary-search.html
Arrays  http://cs-study.blogspot.com/2012/10/arrays.html

May 31, 2015

Networking Terminologies

Please write a brief note on all the terminologies. A quiz will be taken on the following in the upcoming class.


Unshielded Twisted Pair Cables (UTP).
T568-A color Schemes for Straight Through, Cross Over, Roll Over Cables.
T568-B color Schemes for Straight Through, Cross Over, Roll Over Cables.

Network congestion
TCP congestion-avoidance
         
Additive increase/multiplicative decrease
Slow-start
Fast Retransmit and Fast Recovery

FireWall and VPNs
IP Tunnel
Asynchronous Transfer Mode (ATM):-
             Try to cover all the terminologies used in the following tutorial. ATM Tutorial     
    
NS2

Simulator class in NS2
Networking Nodes in NS2 and their features
Types of links available for us to use in NS2
Bandwidth
Latency Time
Queueing Algorithms
TCP
UDP
CBR
FTP
TCP Sink Agent
NULL Agent

.........................
Paper Pattern:

Q1. Theoretical Portion as defined above. Prepare comprehensively.
Q2. NS2 complete. Prepare thoroughly. You will have to write code.
Q3. Do prepare thoroughly for RiverBed. You will have to perform task on riverbed. Following tasks are excluded.

A Shared media network
A direct link network
Small office network



October 29, 2014

Small Office network simulation

Here is the link to the post.

https://www.rivier.edu/faculty/vriabov/Tutotial-com_small_int.pdf





April 22, 2014

Sorted Linked List implementation in C

include "stdio.h"
include "stdlib.h"
include "conio.h"



void del(int data);
void insert(int value);
void display();


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

struct node *top=NULL,*temp, *temp1, *temp2, *temp3;

int main()
{
    int choice,data;

 
    while(1) //infinite loop is used to insert/delete infinite number of elements in linked list
    {
     
        printf("\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
        printf("\nEnter ur choice:");
        scanf("%d",&choice);
        switch(choice)
        {
        case 1:
         
         
            printf("Enter a new element :");
            scanf("%d",&data);
            insert(data);
            break;
         
        case 2:
     
        printf("Enter the value to be deleted from sorted linked list :");
            scanf("%d",&data);
         
            del(data);
            break;
         
        case 3:
            display();
            break;
        case 4:
            exit(0);
        }
     
    }  
getch();
return 0;
}

void insert(int data)
{

temp=(struct node *)malloc(sizeof(struct node));
temp->data=data;

if(top == NULL)
{

            temp->link=NULL;
            top=temp;
         
}
else            // top not null
{
temp1 = top ;
while(temp1 != NULL)
{
if(temp1->data >= data)   // list element is smaller ...

{
if(temp1 == top)   // list element is head ...
{
  temp->link = temp1;

top = temp;
break;

}
else // list element is not head ..
{

temp->link = temp1;
temp2->link = temp;
break;
}

}
else
{

if(temp1->link == NULL)
{
temp->link = NULL;
temp1->link = temp;
break;

}
else
{
temp2 = temp1;
temp1 = temp1->link;
}

}

}

}
          // creating a space for the new element.
                 
}

void del(int data)
{
     struct node *temp,*var;
     temp=top;
 int i=0;
     while(temp!=NULL)
     {
          if(temp->data == data)
          {      i = 1;   // Flag ..
                if(temp==top)
                {
                     top=temp->link;
                     free(temp);
                   break;
                }
                else
                {
                     var->link=temp->link;
                     free(temp);
                     break;
                 
                }
          }
          else
          {
               var=temp;
               temp=temp->link;
          }
     }
     if(i == 1)
     {
printf("data deleted from list is %d",data);
 
     }
     else
     {
      printf("\n The required data, %d is not found in the list. go look somewhere else",data);

     }
}





void display()
{
         temp=top;
            if(temp==NULL)
            {
                printf("\nStack is empty\n");
            }
         
            while(temp!=NULL)
            {
                printf(" %d ->",temp->data);
                temp=temp->link;
            }
             
}

March 12, 2014

Priority Queue Implementation in C using Arrays

#include <stdio.h>

#include <conio.h>

#define size 5

int queue[5][2] = {0};

int top = -1;

int bottom;

void push(int value, int pr)

{

int i,j,k;

if(top < size-1)

{

if(queue[top][1] > pr)

{

for(i=0;i<top;i++)

{

if(queue[i][1] > pr)

{

break;

}

}

for(j=top;j>=i;j--)

{

queue[j+1][0] = queue[j][0];

queue[j+1][1] = queue[j][1];

}

top++;

queue[i][0] = value;

queue[i][1] = pr;

}

else

{

top++;

queue[top][0] = value;

queue[top][1] = pr;

}

}

else

{

printf("queue overflow \n");

}

}

void pop()

{

int i;

if(queue[0][0] == 0)

{

printf("\n The queue is empty  \n");

}

else

{

printf("After , dequeue the following value is erased \n  %d \n", queue[0][0]);

for(i=0;i<top;i++)

{

queue[i][0] = queue[i+1][0];

queue[i][1] = queue[i+1][1];

}

queue[top][0] = 0;

queue[top][1] = 0;

top--;

}

}

void display()

{ int i,j;

printf("Element\tPriority \n");

for(i=size - 1;i>=0;i--)

{

for(j=0;j<2;j++)

{

printf(" %d\t",queue[i][j]);

}

printf("\n");

}

}

int main()

{

int i,j, ch=0 ,value = 0,pr=0;

while(1)

{

printf("\n Please Enter the choice. \n");

printf("1 for Enqueue \n 2 for Dequeue \n 3 for display\n  5 for exit: \t \n");

scanf("%d",&ch);

switch(ch)

{

case 1:

printf("\n Please Enter the number to be inserted: \t ");

scanf("%d", &value);

printf("\n Please Enter the priority: \t ");

scanf("%d", &pr);

push(value,pr);

break;

case 2:

pop();

break;

case 3:

display();

break;

case 5:

exit(0);

default:

printf("You entered wrong choice\n");

}

}

}

C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...