EmbLogic's Blog

Structures using pointers

#include”header1.h”

struct distance *input()
{
struct distance *d1;
d1=(struct distance *)malloc(sizeof(struct distance));
printf(“\nenter the distance in feet”);
scanf(“%d”,&d1->feet);
printf(“\nenter the distance in inches”);
scanf(“%f”,&d1->inches);
return d1;
}

struct distance *add(struct distance *d1, struct distance *d2)
{
struct distance *d4;
d4=(struct distance *)malloc(sizeof(struct distance));
d4->feet=d1->feet+d2->feet;
d4->inches=d1->inches+d2->inches;
if(d4->inches>=12)
{
d4->feet++;
d4->inches=d4->inches-12;
}
return d4;
}

struct distance display(struct distance *d1, struct distance *d2,struct distance *d3)
{
printf(“the distance(%d’ -%f\”)and the distance (%d’-%f\”) (%d’-%f\”)”,d1->feet,d1->inches,d2->feet,d2->inches,d3->feet,d3->inches);
}

int main()
{
struct distance *d1,*d2,*d3;
d1=(struct distance *)malloc(sizeof(struct distance));
d2=(struct distance *)malloc(sizeof(struct distance));
d3=(struct distance *)malloc(sizeof(struct distance));
d1=input();
d2=input();
d3=add(d1,d2);
display(d1,d2,d3);
return 0;
}

Posted in Uncategorized | Leave a comment

c program to compare two string without using string.h

#include
int main()
{
char s1[5],s2[5];
int i,j,flag=0;

printf(“Enter s1:”);
scanf(“%s”,s1);
printf(“Enter s2:”);
scanf(“%s”,s2);
for(i=0;i<5;i++)
{
if(s1[i]!=s2[i])
{
j=s1[i]-s2[i];
flag=1;
printf("return value: %d\n",j);
break;
}
}
if(flag==0)
printf("string matched\n");

return 0;
}

Posted in Data Structures with C | Leave a comment

adding two distances in feet and inches using functions and structure pointers

header file*********************************************************************

#include<stdio.h>
#include<stdlib.h>

struct distance
{    int feet;
int inches;
};
int display(struct distance *,struct distance *,struct distance *);
struct distance * add(struct distance *,struct distance *);
struct distance * input();

**************************************************************************

main file******************************************************************

#include”header.h”
int main()
{
struct distance *d1,*d2,*d3;
d1 = input();
d2 = input();
d3 = add(d1,d2);
display(d1,d2,d3);
return 0;

}
struct distance * input()
{
struct distance *d1;
d1 = (struct distance*)malloc(sizeof(struct distance));
printf(“\nenter the distance in feet”);
scanf(“%d”,&d1->feet);
printf(“\nenter the distance in inches”);
scanf(“%d”,&d1->inches);
return d1;

}
struct distance * add(struct distance *d1, struct distance *d2)
{
struct distance *d3;
d3 = (struct distance*)malloc(sizeof(struct distance));
d3->inches= d1->inches +d2->inches;
d3->feet = d1->feet +d2->feet;
if(d3->inches >= 12)
{    d3->feet++;
d3->inches-=12;
}
return d3;

}
int display(struct distance *d1,struct distance *d2,struct distance *d3)
{
printf(” %d\’ %d\” \n %d\’ %d\” \n —— \n%d\’ %d\” \n “,d1->feet,d1->inches,d2->feet,d2->inches,d3->feet,d3->inches);
}
****************************************************************************

output:::

enter the distance in feet6

enter the distance in inches7

enter the distance in feet6

enter the distance in inches7
6′ 7″
6′ 7″
——
13′ 2″

Posted in Data Structures with C, Project 2: Multiple Data Compression and Encryption | Leave a comment

Interrupts in Parallel Port

  • A parallel port can generate interrupts when the voltage level on a certain input pin changes. The parallel port has to be instructed explicitly to generate interrupts and it is also possible to inhibit interrupts (e.g., while serving a previous interrupt).
  • The parallel port consists of three bytes in the I/O address space of the PC:
    1. The first byte is used as data port: 8 bits of output, often labelled D0 to D7, with D0 being the least significant bit and D7 the most significant.
    2. The second byte is used as status port: 5 bits of input (S3 – S7), 3 bits unused (S0 – S2)
    3. The third byte is used as control port:  4 bits of output (C0 – C3), 4 bits setup/unused (C4 – C7)
  • Traditionally, IBM PC systems have allocated their first two parallel ports according to the configuration in the table below:

PORT NAME     Interrupt #     Starting I/O   Ending I/O LPT1           IRQ 7          0×378           0x37f LPT2           IRQ 5           0×278           0x27f

  • In this exercise we use LPT1 with IRQ 7 and the following three bytes:
    1. 0×378 : data port
    2. 0×379 : status port
    3. 0x37A : control port
  • The parallel port standard states that setting bit C4 of the control port (0x37A) enables interrupt reporting.

The pins of the 25 pin female D type parallel port connector are shown in the following picture

  • In this picture all green pins (numbered 18 – 25) are grounded at 0 Volt.
  • When having interrupts enabled (i.e., bit C4 has been set), an interrupt will be generated by the parallel port when the voltage on input line S6 (pin 10) is raised from 0 Volt to +5 Volt. By default the input line is kept high to +5 Volt when nothing is connected. Observe that when pin 10 is shortly shorted to one of the pins 19-25, i.e., to ground, an interrupt on IRQ line 7 will be generated by the parallel port. The interrupt is generated at exactly the moment that you undo the shortage, since at that exact moment the line is raised from 0 to +5 Volt.

http://www.pstnet.com/internal/kbimage/1320-1.gif

 

Posted in Parallel Port Driver | Leave a comment

link list operation

—test——–
#! /bin/bash
rcs -i header.h
rcs -i llist_ato_sir.c
ci header.h
ci llist_ato_sir.c
co header.h
co llist_ato_sir.c
gcc -o result llist_ato_sir.c
./result
rm -rf header.h
rm -rf llist_ato_sir.c
rm -rf result

//——-header file——
@#include
#include
struct link
{
int info;
struct link *next;
};
static int node_no=0;
struct link *creat_node();
struct link *delete_node(struct link *);
int delete_at_end(struct link *);
struct link* delete_at_beg(struct link *);
int delete_at_pos(struct link *);
struct link * delete_key(struct link *);
struct link *insert_node(struct link *);
struct link *node_at_beg(struct link *);
int node_at_pos(struct link *);
int node_at_end(struct link *);
int node_key(struct link *);
int traverse_ll(struct link *);
int getchoice(int );
int search_element(struct link *);
@

//—————link list main function——–
@#include”header.h”
struct link *create_node()
{

struct link *temp;
temp=(struct link *)malloc(sizeof(struct link));
printf(“\n enter the data :”);
scanf(“%d”,&temp->info);
temp->next=NULL;
node_no++;
return temp;
}
delete_at_end(struct link *temp)
{
struct link *end,*p;
end=temp;
while(end->next!=NULL)
{
p=end;
end=end->next;
}
p->next=NULL;
free(end);
return 0;
}

struct link* delete_at_beg(struct link *temp)
{
struct link *beg;
beg=temp;
temp=beg->next;
free(beg);

return temp;
}
delete_at_pos(struct link *temp)
{
int node,i;
struct link *nnode=temp,*pnode=temp,*r=NULL;
printf(“\n you have %d node”,node_no);
printf(“\n which node you want to delete”);
scanf(“%d”,&node);
if(node==2)
{

struct link *p,*q;

p=temp->next;
q=p->next;
temp->next=q;

free(p);
node_no–;

}
else
{
for(i=0;inext;

}

for(i=0;inext;

}
pnode->next=nnode;
node_no–;
}
return 0;

}
struct link *delete_key(struct link *temp)
{
int val,flag=0;
struct link *p=temp,*r;
printf(“\n enter the value whose node you want to delete :\n”);
scanf(“%d”,&val);
if(val==temp->info)
{
flag=1;
node_no–;
temp=temp->next;
free(p);
return temp;
}
else
{
while(p!=NULL)
{
if(p->info==val)
{
r->next=p->next;
flag=1;
node_no–;
free(p);
break;

}
r=p;
p=p->next;

}
}
if(flag==0)
{
printf(“\n entered data is not present in link list \n”);

}
return temp;
}
struct link*delete_node(struct link *temp)
{

printf(“\n\t 1.delete node at begining”);

printf(“\n\t 2. delete node at position”);
printf(“\n\t 3.delete node at end”);
printf(“\n\t 4.delete node at key value”);
int choice;
printf(“\n enter your choice :”);
scanf(“%d”,&choice);

switch(choice)
{
case 1:
temp=delete_at_beg(temp);
break;
case 2:
delete_at_pos(temp);
break;
case 3:
delete_at_end(temp);
break;
case 4:
temp=delete_key(temp);
break;
default:
printf(“\n \aenter right choice”);
}
return temp;
}

/*struct link *delete_node(struct link *temp)
{
int node,i;
struct link *nnode=temp,*pnode=temp,*r=NULL;
printf(“\n you have %d node”,node_no);
printf(“\n which node you want to delete”);
scanf(“%d”,&node);
if(node==1)
{
struct link *q;
//q=(struct link *)malloc(sizeof(struct link));
q=temp;
temp=temp->next;

free(q);

node_no–;
}
else if(node==2)
{
// nnode=temp->next;
// nnode=nnode->next;
struct link *p,*q;
p=(struct link *)malloc(sizeof(struct link));
p=temp->next;
q=temp->next;
q=q->next;
//temp->next=temp->next->next;

free(p);
node_no–;

}
else
{
for(i=0;inext;

}

for(i=0;inext;
}
pnode->next=nnode;
node_no–;
}
return temp;
}*/
struct link *node_at_beg(struct link *temp)
{
struct link *beg;
beg=create_node();
beg->next=temp;

return beg;
}
node_at_pos(struct link *temp)
{
int position,i;
struct link *new,*pos=temp;
printf(“\n no. of node in link list :%d”,node_no);
printf(“\n please enter the position where you want to insert node :”);
scanf(“%d”,&position);
if(position>node_no)
{
printf(“\n enter the position less than total node ..!!”);
goto out;
}
new=create_node();
for(i=1;inext;
}
new->next=pos;
for(i=1;inext;
}
temp->next=new;
return 0;
out:
return 0;
}
node_at_end(struct link *temp)
{
struct link *end;

end=create_node();
while(temp->next!=NULL)
{
temp=temp->next;
}

temp->next=end;
return 0;
}

node_key(struct link *temp)
{
int val,count=0;

struct link *key=temp,*insert;
printf(“\n enter the key value where you want to add node :”);
scanf(“%d”,&val);
while(key!=NULL)
{
if(val==key->info)
{
insert=create_node();
insert->next=key->next;
key->next=insert;
count++;
break;
}
key=key->next;
}
if(count==0)

printf(“\n key value is not present in link list”);
return 0;
}
struct link *insert_node(struct link *temp)
{
printf(“\n\t 1.insert node at begining”);

printf(“\n\t 2. insert node at position”);
printf(“\n\t 3.insert node at end”);
printf(“\n\t 4.insert node at key value”);
int choice;
printf(“\n enter choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
temp=node_at_beg(temp);
break;
case 2:
node_at_pos(temp);
break;
case 3:
node_at_end(temp);
break;
case 4:
node_key(temp);
break;
default:
printf(“\n \aenter right choice”);
}

return temp;
}

traverse_llist(struct link *temp)
{
while(temp!=NULL)
{
printf(“\n node no.—> %d”,temp->info);
temp=temp->next;
}
return 0;
}
search_element(struct link *temp)
{
int no,count=0,flag=0;
printf(“\n enter the no. which you want to search :”);
scanf(“%d”,&no);
while(temp!=NULL)
{
count++;
if(no==temp->info)
{
flag=1;
printf(“\nyour search for %d found”,no);
break;
}
temp=temp->next;
}
if(flag==0)
{
printf(“\nyour searching no. is not present in link list”);
}
return 0;
}
getchoice(int choice)
{

static int flag=0;
struct link *new,*start;
switch(choice)
{

case 1:
if(flag==0)
{
new=start=create_node();
printf(“\n link list created”);
flag=1;
}
else
printf(“\n link list created already”);
break;

case 2:
if(flag==1)
new=insert_node(new);
else
printf(“\n create link list first”);
break;
case 3:
if(flag==1)
new=delete_node(new);
else
printf(“\n create link list first”);
break;
case 4:
if(flag==1)
traverse_llist(new);
else
printf(“\n create link list first”);
break;
case 5:
search_element(new);
break;
case 6:
// sorting_element();
break;
default:
printf(“enter right choice”);

case 0:
exit(0);

}
return 0;

}

int main()
{
int choice;
printf(“——-MAIN MENU———-”);
while(1)
{
printf(“\n 1.CREATE LINk LIST———”);
printf(“\n 2.INSERT NODE————–”);
printf(“\n 3.DELETE NODE————–”);
printf(“\n 4.TRAVERSE LINK LIST——-”);
printf(“\n 5.SEARCHING ELEMENT________”);
printf(“\n 6.SORTING ELEMENT__________”);
printf(“\n 0.EXIT LINKLIST___________”);
printf(“\n enter choice :”);
scanf(“%d”,&choice);
getchoice(choice);
}
return 0;
}

Posted in Uncategorized | Leave a comment

c program to concatinate two string without using string.h

#include
#include
int main()
{
char a[20]={0},b[10]={0};
int i,j=0;
printf(“Enter name1:\n”);
scanf(“%s”,a);
printf(“Enter second name:\n”);
scanf(“%s”,b);
for(i=0;i<20;i++)
{
if(a[i]=='')
{
a[i]=b[j];
j++;

}
}
printf("Concatination is: %s\n",a);

return 0;

}

Posted in Data Structures with C | Leave a comment

different operation on link list

operation on link list which i’ve performed:
1.creation of link list,
2.insertion of node
a.at begining,
b.at end,
c.at any position
d.at any key value(if a certain element is present then insert this node)
3.traverse on link list
4.searching of any element
5.deletion of node
a.deletion of first most node
b.at end
c.at any position
d.at key value(deletion of a particular element)
————————
RCS file: llist_ato_sir.c,v
Working file: llist_ato_sir.c
head: 1.24
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 24; selected revisions: 24
description:
created the main menu
accroding to main menu ,i’ve made a choice function
which has the function call of all choices
—————————-
revision 1.24
date: 2014/07/11 08:49:37; author: root; state: Exp; lines: +1 -1
resolve error
—————————-
revision 1.23
date: 2014/07/11 08:47:33; author: root; state: Exp; lines: +8 -1
correct the problem of insert_node_pos()
keeping the entered node position less than total node
—————————-
revision 1.22
date: 2014/07/11 08:42:15; author: root; state: Exp; lines: +1 -1
resolve the error
—————————-
revision 1.21
date: 2014/07/11 08:40:54; author: root; state: Exp; lines: +1 -1
give the argument to search_element function
base address is argument
—————————-
revision 1.20
date: 2014/07/11 08:39:55; author: root; state: Exp; lines: +25 -7
define the search_element function
—————————-
revision 1.19
date: 2014/07/11 08:25:22; author: root; state: Exp; lines: +15 -3
make the delete_key for compatible for first node
for doing this i’ve used if else condition
—————————-
revision 1.18
date: 2014/07/11 08:03:10; author: root; state: Exp; lines: +13 -7
resolve the problem of delete_key()
—————————-
revision 1.17
date: 2014/07/11 07:50:06; author: root; state: Exp; lines: +20 -0
giving definition to delete_key function
this function take the value
if that value is present in any node
then that node will deleted
—————————-
revision 1.16
date: 2014/07/11 05:01:09; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.15
date: 2014/07/11 04:57:52; author: root; state: Exp; lines: +8 -5
given definition of delete_at_beg()
—————————-
revision 1.14
date: 2014/07/11 04:51:50; author: root; state: Exp; lines: +4 -3
correct the error in function delete_nod_pos()
for position 2
—————————-
revision 1.13
date: 2014/07/11 04:46:39; author: root; state: Exp; lines: +38 -0
definr delete_at_pos() function
—————————-
revision 1.12
date: 2014/07/11 04:14:35; author: root; state: Exp; lines: +8 -6
*** empty log message ***
—————————-
revision 1.11
date: 2014/07/11 03:57:36; author: root; state: Exp; lines: +2 -3
modify the delete_node()
—————————-
revision 1.10
date: 2014/07/11 03:54:17; author: root; state: Exp; lines: +55 -13
making function for delete operation
define delete_node()
then defined delete_at_end() only for now
—————————-
revision 1.9
date: 2014/07/11 03:25:22; author: root; state: Exp; lines: +3 -2
puting the header file in header.h
—————————-
revision 1.8
date: 2014/07/11 01:44:38; author: root; state: Exp; lines: +25 -12
created inser at key value function
this function insert node when the key value(if a certain value is present)
then it will insert a node
—————————-
revision 1.7
date: 2014/07/10 14:12:57; author: root; state: Exp; lines: +43 -20
creating insertion at key value
—————————-
revision 1.6
date: 2014/07/10 10:07:09; author: root; state: Exp; lines: +94 -6
*** empty log message ***
—————————-
revision 1.5
date: 2014/07/10 03:08:51; author: root; state: Exp; lines: +6 -1
*** empty log message ***
—————————-
revision 1.4
date: 2014/07/10 02:27:34; author: root; state: Exp; lines: +51 -5
created the insert node function
in which we can insert node at beg,at end and at any position
but for now i’ve only made insertion of node at end
—————————-
revision 1.3
date: 2014/07/10 01:57:31; author: root; state: Exp; lines: +28 -8
making the traverse function
—————————-
revision 1.2
date: 2014/07/10 01:41:22; author: root; state: Exp; lines: +13 -1
created the link list function
—————————-
revision 1.1
date: 2014/07/10 01:27:12; author: root; state: Exp;
Initial revision
=============================================================================
———-header.h file—————
RCS file: ./header.h,v
Working file: header.h
head: 1.6
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 6; selected revisions: 6
description:
created header in which declare all the header file and the
function prototype
—————————-
revision 1.6
date: 2014/07/11 08:39:30; author: root; state: Exp; lines: +1 -1
declare the prototype of search_element function
—————————-
revision 1.5
date: 2014/07/11 08:24:50; author: root; state: Exp; lines: +1 -1
change the return type of delete_key();
—————————-
revision 1.4
date: 2014/07/11 05:00:28; author: root; state: Exp; lines: +1 -1
modify the prototype of delete_node_at_beg()
—————————-
revision 1.3
date: 2014/07/11 04:13:43; author: root; state: Exp; lines: +1 -1
correct the declaration of delete_key()
—————————-
revision 1.2
date: 2014/07/11 03:51:55; author: root; state: Exp; lines: +4 -0
decleared the prototype of delete_node
in reference to delete the is also four delete position declearation
—————————-
revision 1.1
date: 2014/07/11 03:25:22; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Data Structures with C | Leave a comment

c program to concatinate two string without using

#include
#include
int main()
{
char a[20]={0},b[10]={0};
int i,j=0;
printf(“Enter name1:\n”);
scanf(“%s”,a);
printf(“Enter second name:\n”);
scanf(“%s”,b);
for(i=0;i<20;i++)
{
if(a[i]=='')
{
a[i]=b[j];
j++;

}
}
printf("Concatination is: %s\n",a);

return 0;

}

Posted in Data Structures with C, Uncategorized | Leave a comment

comparing strings which are given by the user & displaying the result on the screen…..

1 #include<stdio.h>
2 #include<string.h>
3
4 int main()
5 {
6   int n1,n2,i;
7
8         printf(“\n\nfirst enter the number of max. words u will enter in each strings  “);
9         printf(“\n\nin first string words u will use are : “);
10         scanf(“%d”,&n1);
11         printf(“\n\nin second string words u will use are : “);
12         scanf(“%d”,&n2);
13
14   char s1[n1],s2[n2];
15
16         printf(“\n\nnow enter first string :  “);
17         scanf(“%s”,&s1);
18         printf(“\n\nnow enter second string :  “);
19         scanf(“%s”,&s2);
20
21         if(n1>n2)
22         {
23                 for(i=0;i<n1;i++)
24                 {
25                         if(s1[i]>s2[i])
26                         {
27                                 printf(“\n\nthe first string is greater than second\n\n”);
28                                 goto x;
29                         }
30
31                         else if(s1[i]<s2[i])
32                         {
33                                 printf(“\n\nthe first string is less                        than second\n\n”);
34                                 goto x;
35                         }
36                 }
37         }
38
39
40
41         else if(n1<n2)
42         {
43                 for(i=0;i<n2;i++)
44                 {
45                         if(s1[i]>s2[i])
46                         {
47                                 printf(“\n\nthe first string is greater than second\n\n”);
48                                 goto x;
49                         }
50
51                         else if(s1[i]<s2[i])
52                         {
53                                 printf(“\n\nthe first string is less than second\n\n”);
54                                 goto x;
55                         }
56                 }
57         }
58
59
60
61         else if(n1==n2)
62         {
63                 for(i=0;i<n2;i++)
64                 {
65                         if(s1[i]>s2[i])
66                         {
67                                 printf(“\n\nthe first string is greater than second\n\n”);
68                                 goto x;
69                         }
70
71                         else if(s1[i]<s2[i])                                 72                         {
73                                 printf(“\n\nthe first string is less than second\n\n”);
74                                 goto x;
75                         }
76                 }
77         }
78
79
80 x:return 0;
81 }

Posted in Data Structures with C | Leave a comment

Program to combine two words without string char or compair

#include<stdio.h>

int main()

{

char j,i,a[15]=”hello”,b[15]=”world”,**p;

while(a[i]!=”)

{

i++;

}

for(j=0;b[j]!=”;j++)

{

a[i+j]=b[j];

}

printf(“%s”a)

 

}

Posted in Uncategorized | Leave a comment

c program to find string length using string.h

#include
#include
int main()
{
char s1[]=”Amar”,s2[]=”deep rawat”;
int i,j;
j=strcmp(s1,s2);
if(j>0)
printf(“S1 is greater than S2\n”);
if(j<0)
printf("S1 is smaller than s2\n");
strcat(s1,s2);
printf("Concatination is:%s\n",s1);
i=strlen(s1);
printf("Length of string after concatination is:%d\n",i);

return 0;
}

Posted in Data Structures with C | Leave a comment

c program to print string and find its leght without using

#include

int main()
{
char p[]=”amardeep singh rawat”;
int i=0;
int count=0;
printf(“String elemen are:\n”);
while(p[i]!=”)
{
printf(“%c\n”,p[i]);
i++;
count++;
}
printf(“string is:%s\n”,p);
printf(“Length of string is:%d\n”,count);
return 0;
}

Posted in Data Structures with C | Leave a comment

2 bit & 3 bit compression- decompression . a different approach.

the approach is to stuff all the 24(3bit lcm of 3 and 8) bits into an integer variable, and then writing into the file from that int variable taking 1 byte at a time.**

in 2 bit compression the 4  index codes(2 bit each) is stuffed into a byte using iterations and then written into the file.

similar strategies are used at the time of decompression..

// 2 bit compression**********************************************************************

int compress2(int *fd,char *ma,int *cl)
{
int cfd,j;
unsigned char i1,ch,byt;
cfd =open(“encry”,O_CREAT | O_RDWR,0666);
lseek(*fd, 0,  SEEK_SET);
while(1)
{
byt = byt ^ byt;
for( j = 6; j >= 0; j -= 2)
{
if(!(read(*fd, &ch, 1)) && ch == 10)
goto o;
i1 =(char) findl( ch, ma);
i1 = i1<<(j);
byt = byt | i1;
}

write(cfd, &byt, 1);
}

o:        write(cfd, &byt, 1);
return cfd;
}

// 3bit compression************************************************************************
int compress3(int *fd,char *ma,int *cl)
{
int cfd,i,j,m,flag=0;
unsigned int k,p;
unsigned char ch,b;
cfd =open(“encry”,O_CREAT | O_RDWR,0666);
lseek(*fd, 0,  SEEK_SET);
while(1)
{    k=0;j=0,m=1;
for(i=8 ; i <= 29; i+=3)
{
p=0;
if(!(read(*fd, &ch, 1)) && ch == 10 )
{flag=1;
goto o;}
p = findl( ch, ma ) ;
p = p << 29;
p = p >> i;
k = k|p;
if(j++ == 2)
{j=0;m++;}
}
o:        printf(“\nm:%d”,m);
for( i = 8 ; i <= 8*m ;i+=8 )
{
b = b^b;
p = k;
p= p << i;
p= p >> 24;
b =(char)p;
if(b==0)break;
//    printf(“\nhey:%d p: %d\n”, b,p);
write(cfd, &b, 1);
}

if (flag == 1) break;
}

return cfd;
}

//2 bit decompression*******************************************************************************

int decompress2(int *cfd, char *ma)
{
unsigned char ch,i1,i2;
int rfd,l=0,m=0;
rfd = open(“dec”,O_CREAT|O_RDWR,0666);
lseek(*cfd, 0, SEEK_SET);
while(read(*cfd, &ch, 1) && ch != 10)
{
l = 0;
while(l<=6 && m<=len)
{
i1 = ch;
i1 = i1 << l;
i1 = i1 >> 6;
l+=2;
m++;
printf(” %d = %c\n”,i1, *(ma+i1));
write(rfd, (ma+i1), 1);
}
}
}

//3 bit decompression************************************************************************
int decompress3(int *cfd, char *ma)
{
unsigned char ch,i1,i2;
int rfd,i,h;
unsigned int m,n,p;
rfd = open(“dec”,O_CREAT|O_RDWR,0666);
lseek(*cfd, 0, SEEK_SET);
while(1)
{
m = 0;
for(i=16; i >= 0; i -= 8)
{
ch = 0;p=0;
if(!(read(*cfd, &ch, 1)) || ch == 10)
goto o;
p = ch<<i;
m = m | p;
printf(“\n%d %d %d\n”,i,m,ch);
}
o:    for(i=8 ; i<=29; i+=3)
{
n = 0;
n = m;
n = n << i;
n = n >> 29;
if(n == 0 && ++h  == len-2)goto l;
printf(“\n %d = %c\n”,i,*(ma+n));
write(rfd , (ma+n),1);
}

}
l:
return rfd;
}

Posted in Uncategorized | Leave a comment

MDC completed upto 4 bit Compression and Decompression


RCS file: mdc.c,v
Working file: mdc.c
head: 1.11
branch:
locks: strict
	root: 1.11
access list:
symbolic names:
keyword substitution: kv
total revisions: 11;	selected revisions: 11
description:
This is the program for compression of file.
----------------------------
revision 1.11	locked by: root;
date: 2014/07/03 17:16:22;  author: root; 
state: Exp;  lines: +15 -17
*** empty log message ***
----------------------------
revision 1.10
date: 2014/07/03 17:07:40;  author: root; 
state: Exp;  lines: +4 -11
Code optimisation and removal of debugging
statements.
Compression and Decompression are currently in
the same C program.
Writing decompression in diff c program next.
----------------------------
revision 1.9
date: 2014/07/03 16:54:57;  author: root; 
state: Exp;  lines: +79 -19
Compression and decompression for 4 bit
implemented.
----------------------------
revision 1.8
date: 2014/07/01 18:27:43;  author: root; 
state: Exp;  lines: +90 -37
implemented 4 bit data compression using
compression4().
the compressed data from file is being written
to comfile.txt 
zipwrite() name has been updated.
----------------------------
revision 1.7
date: 2014/06/30 15:23:32;  author: root; 
state: Exp;  lines: +52 -4
compression() added and related compression
functions for
testing.[compression2(),compression3(),......compression7()].Removed
all debugging statements.
----------------------------
revision 1.6
date: 2014/06/30 15:08:58;  author: root; 
state: Exp;  lines: +17 -16
made masterarray local to main().
----------------------------
revision 1.5
date: 2014/06/28 19:43:49;  author: root; 
state: Exp;  lines: +26 -4
finding codelength for the no of distinct
characters in file.
/
----------------------------
revision 1.4
date: 2014/06/28 19:23:09;  author: root; 
state: Exp;  lines: +6 -6
returned ndc from copy_masterarray function to
obtain no of distinct characters
----------------------------
revision 1.3
date: 2014/06/28 18:42:56;  author: nitesh; 
state: Exp;  lines: +2 -1
calculated ndc
----------------------------
revision 1.2
date: 2014/06/28 17:51:11;  author: nitesh; 
state: Exp;  lines: +54 -34
this program generates an array of distinct
characters of file.
----------------------------
revision 1.1
date: 2014/06/28 16:02:14;  author: nitesh; 
state: Exp;
Initial revision
=============================================================================
Posted in Uncategorized | Leave a comment

Log Circular Queue.

Circular Queue Implementation completed successfully.

 

RCS file: queue_cir.c,v
Working file: queue_cir.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
Implemented the circular queue using arrays.
Revision 1.1 Testing circular queue
—————————-
revision 1.1 locked by: root;
date: 2014/07/07 20:31:57; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment