EmbLogic's Blog

multiple data compression

@#include
32 #include
33 #include
34 #include
35 int main()
36 {
37 char arr[55],m[55],ch1,ch2;
38 int fd,j,ret,i=0,len;
39 fd =open(“text”,O_RDONLY);
40 read(fd,&arr,55);
41 len=strlen(arr);
42 printf(“lenght of string is %d\n”,len);
43 if(fd<0)
44 {
45 perror("read");
46 exit(-1);
47
48 }
49 for(i=0;i<len;i++)
50 {
51 printf("%c\n",arr[i]);
52 }
53 printf("the master array is=");
54 int size;
55 size=1;
56 for(i=0;i<len;i++)
57 {

for(j=0;j<=size;j++)
59 {
60 if((j+1)==size)
61 {
62 m[j]=arr[i];
63 size=size++;
64 break;
65 }
66 else
67 {
68 if(m[j]==arr[i])
69 {
70 break;
71 }
72 }}
73 }
74
75 for(j=0;j<=size;j++)
76 {
77 printf("%c\n",m[j]);
78 }
79 return 0;
80 }
81
82 @
83
84
85 1.1
86 log
87 @Initial revision
88 @
89 text
90 @d7 2

Posted in Uncategorized | Leave a comment

THREADS(using array)

RCS file: thread1.c,v
3 Working file: thread1.c
4 head: 1.1
5 branch:
6 locks: strict
7         root: 1.1
8 access list:
9 symbolic names:
10 keyword substitution: kv
11 total revisions: 1;     selected revisions: 1
12 description:
13 program of threads
14 array is created
15 using for loop thread is created 10 times
16 it run sucessfully
17 —————————-
18 revision 1.1    locked by: root;
19 date: 2014/03/28 13:32:33;  author: root;  state: Exp;
20 Initial revision
21 =============================================================================
~
~
~
~
~
~

Posted in Uncategorized | Leave a comment

2 threads made

#include<stdio.h>
2 #include<stdlib.h>
3 #include<pthread.h>
4
5 void* mine_thread(void *arg);
6 void* mine_thread1(void *arg);
7
8 int main()
9 {
10         int ret,set;
11         int z=5,y=6;
12         void * result=malloc(5);
13         void * result1=malloc(5);
14         pthread_t a,b;
15
16         ret=pthread_create(&a,NULL,mine_thread,(void*)&z);//////creating thread
17         pthread_join(a,&result);////wait for the thread specified by thread to terminate
18
19         set=pthread_create(&b,NULL,mine_thread1,(void*)&y);
20         pthread_join(b,&result1);
21
22         sleep(5);
23         printf(“result=%s\n”,result);
24         printf(“result1=%s\n”,result1);
25 }
26
27 void* mine_thread(void *arg)///function of thread
28 {
29                 int a1;
30                 a1=*(int*)arg;
31                 printf(“value of a1 =%d\n”,a1);
32                 pthread_exit(“bye”);
33 }
34
1,8
result will be:-

a1=5

b1=6

result=bye

result1=take care

Posted in Uncategorized | Leave a comment

starting threads

Implement two threads

 

RCS file: ./threads.c,v
Working file: ./threads.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;	selected revisions: 0
description:
implement threds on two child
=============================================================================
Posted in Uncategorized | Leave a comment

Bench Calculator.

Faced with the limitations of the shell command expr and other shell constructs, let’s set out to explore the powerful command bc, which stands for bench calculator. This is not just a command or tool, but a complete language in itself. And its power lies in its arbitrary preciseness with not only integers, but with real numbers. If you are wondering what that means, its computation is usually not limited by the size of the integer or real number types, unlike in most programming languages. Thus, this is closer to our day-to-day use of mathematics, abstracting away the internal details of the computer’s precision. So, let’s get started with the first bits of math, and then move on to more involved aspects like variables, conditionals, and still later on, functions and recursion.

Basic operations
For integer-only math, you can invoke the bench calculator as bc. For full-fledged real number math, invoke it as bc l. Once invoked, it will print a welcome message and then wait for you to type your math statements, before pressing Enter to get your answer. To quit bc, enter Ctrl-D on an empty line. All the basic arithmetic operations: addition (+), subtraction (-), multiplication (*), quotient (/), remainder (%), power (^), and brackets (()) are just there with C-language-like precedence and associativity rules.

[root@localhost]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
2 + 2 * 3 - 5 + 21 / 4 * 6 # A basic maths statement
33
(2 ^ 2) ^ 3 # Another one, with power & brackets
64
^D
Posted in Uncategorized | Leave a comment

Walkie-talkie chatting operation using message queue in two different process

RCS file: mesg1.c,v
Working file: mesg1.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;    selected revisions: 1
description:
IN this program work as the walkie talkie half duplex mode….
There are two processes that are communicating through each other through messagequeue
IN walkie talkie there is a HOLD key here there is a (key-swap) ,if we write swap then the processes are swapped
and now the 2nd process becomes the transmitter process and the first process becomes the receiver process
and viceversa you can do it by sending the word(swap) to other process.

SUCCESSFULLY EXECUTED!!!!!!!!!
—————————-
revision 1.1    locked by: root;
date: 2014/03/27 17:57:18;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

FIFO

       A FIFO special file (a named pipe) is similar to a pipe, except that
       it is accessed as part of the filesystem.  It can be opened by
       multiple processes for reading or writing.  When processes are
       exchanging data via the FIFO, the kernel passes all data internally
       without writing it to the filesystem.  Thus, the FIFO special file
       has no contents on the filesystem; the filesystem entry merely serves
       as a reference point so that processes can access the pipe using a
       name in the filesystem.

       The kernel maintains exactly one pipe object for each FIFO special
       file that is opened by at least one process.  The FIFO must be opened
       on both ends (reading and writing) before data can be passed.
       Normally, opening the FIFO blocks until the other end is opened also.

       A process can open a FIFO in nonblocking mode.  In this case, opening
       for read-only will succeed even if no-one has opened on the write
       side yet, opening for write-only will fail with ENXIO (no such device
       or address) unless the other end has already been opened.

       Under Linux, opening a FIFO for read and write will succeed both in
       blocking and nonblocking mode.  POSIX leaves this behavior undefined.
       This can be used to open a FIFO for writing while there are no
       readers available.  A process that uses both ends of the connection
       in order to communicate with itself should be very careful to avoid
       deadlocks.

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

FIFO

fifo is just similar to pipe as its second name suggest which is named pipe… In fifo and pipe first difference is pipe cannot be seen in directory but named pipe(fifo ) can be accessed or seen inside the pipe and pipe cannot communicate between two seperate processes while at same time fifo can be used between two non relating processes which is having originated from same ancestors in the past.
for creating fifo you need
mkfifo(“fifo name ” , mode in which you want to make pipe(for ex 777));
fifo can be accessed in only one mode at a time that can be in read mode(O_RDONLY) or write mode(O_WRONLY) to get there file descriptor you just need to type a command
readfd=open(“fifo name “, O_RDONLY)
writefd=open(“fifo name “, O_WRONLY)
so open command will return the file descriptor as demanded in the command and you can use it.
if you open the read file descriptor in one process so you need to open file descriptor on other side in write mode otherwise it will be on blocking mode…..

Posted in Uncategorized | Leave a comment

IPC using PIPE

head 1.3;
access;
symbols;
locks
arjun:1.3; strict;
comment @ * @;

1.3
date 2014.03.27.06.05.30; author arjun; state Exp;
branches;
next 1.2;

1.2
date 2014.03.25.08.06.10; author arjun; state Exp;
branches;
next 1.1;

1.1
date 2014.03.25.05.16.16; author arjun; state Exp;
branches;
next ;

desc
@we are using 2 pipe for requesting client and same for processing client
but not use switch case in server.
@

1.3
log
@we are facing problem to read the data from client
@
text

Posted in Uncategorized | Leave a comment

structures in c

Structures in c

A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.

Further Uses of Structures
A structure is a good way of storing related data together.It is also a good way of representing certain types of information. Complex numbers in mathematics inhabit a two dimensional plane (stretching in real and imaginary directions). These could easily be represented here by

struct complex
{
double real;
double imag;
}
doubles have been used for each field because their range is greater than floats and because the majority of mathematical library functions deal with doubles by default.
Structures can also be used as
1. Members of other structures.
2. Arrays of structures are possible, and are a good way of storing lists of data with regular fields,
such as databases.
3. Use to creat link list, trees and other connected structures.

Posted in Uncategorized | Leave a comment

ipc-

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

Inter Process Communication-synchronised by semaphore

RCS file: server.c,v
Working file: server.c
head: 1.3
branch:
locks: strict
saurabh: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
here we are doing a project called ipc ,we have taken a server where three clients simultaneously sending their request over a single fifo.
That mean three clients respectively will send their request to server on a same fifo at a same time ….thus a concept of semaphore arises
this helps in seperating the one client req from others or from being messy!!!! we used semaphore ….
one client request is send over fifo one at a tym.
—————————-basically it synchronised the data coming to server…..
revision 1.3 locked by: saurabh;
date: 2014/03/27 11:12:28; author: saurabh; state: Exp; lines: +10 -0
server has passed the result accurately to all requesting clients.
finally it works :P
—————————-
revision 1.2
date: 2014/03/26 19:30:52; author: saurabh; state: Exp; lines: +17 -8
updated
—————————-
revision 1.1
date: 2014/03/26 17:50:36; author: saurabh; state: Exp;
Initial revision

Posted in Project 03: Client Server Communication using Linux and IPC, Uncategorized | Leave a comment

Program to insert,delete,edit node using structure pointer

head 1.2;
access;
symbols;
locks
root:1.2; strict;
comment @ * @;

1.2
date 2014.03.27.10.38.34; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.03.26.10.31.39; author root; state Exp;
branches;
next ;

desc
@complete program without display fuction
@

1.2
log
@this is complete program
@
text

Posted in Uncategorized | Leave a comment

Difference b/w character array and string array

At the end, string array return a null character

but in case of character array it will not happen

Posted in Uncategorized | Leave a comment

how to insert and delete elements in linked list at various position

head 1.1;
access;
symbols;
locks
root:1.1; strict;
comment @ * @;

1.1
date 2014.03.27.10.47.56; author root; state Exp;
branches;
next ;

desc
@@

1.1
log
@Initial revision
@
text
@#include
#include
struct node
{
int data;
struct node * next;
};
struct node * create_ll( );
struct node * insert_ll(struct node * );
struct node * insert_beg(struct node * );
struct node * insert_pos(struct node * );
struct node * insert_end(struct node * );
struct node * delete_ll(struct node * );
struct node * delete_beg(struct node * );
struct node * delete_pos(struct node * );
struct node * delete_end(struct node * );
struct node * display_ll(struct node * );
int main()
{
struct node * start;
int ch;
do
{
printf(“\n1 create linklist”);
printf(“\n2 insert linklist”);
printf(“\n3 delete linklist”);
printf(“\n4 display linklist”);
printf(“\n5 quit”);
printf(“\n enter the choice”);
scanf(“%d”,&ch);

switch(ch)
{
case 1:
start=create_ll();
break;
case 2:
start=insert_ll(start);
break;
case 3:
start=delete_ll(start);
break;
case 4:
start=display_ll(start);
break;
}
}while(ch != 5);
return 0;
}
struct node * create_ll()
{
struct node * temp;
temp=malloc(sizeof(struct node));
printf(“enter the data”);
scanf(“%d”,&temp->data);
temp->next=NULL;
return temp;
}
struct node * insert_ll(struct node * start )
{
int ch;
printf(“\n1 insert at the beg”);
printf(“\n2 insert at the pos”);
printf(“\n3 insert at the end”);
printf(“\n enter the choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
start=insert_beg(start);
break;
case 2:
start=insert_pos(start);
break;
case 3:
start=insert_end(start);
break;

}

return start;
}
struct node * delete_ll(struct node * start )
{
int ch;
printf(“\n1 delete at the beg”);
printf(“\n2 delete at the pos”);
printf(“\n3 delete at the end”);
printf(“\n enter the choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
start=delete_beg(start);
break;
case 2:
start=delete_pos(start);
break;
case 3:
start=delete_end(start);
break;
}
return start;
}

struct node * display_ll(struct node * start)
{
struct node * temp;
temp=start;
while(temp!=NULL)
{
printf(“entered data is %d”,temp->data);
temp=temp->next;

}
return start;
}
struct node * insert_beg(struct node * start)
{
struct node * temp;
temp=create_ll();
temp->next=start;
start=temp;
return start;

}
struct node * insert_pos(struct node * start)
{
int i,n;
struct node * temp,* new;
temp=start;
new=create_ll();
printf(“enter the position to be inserted”);
scanf(“%d”,&n);
for(i=0;inext;
}
new->next=temp->next;
temp->next=new;
return start;

}
struct node * insert_end(struct node * start)
{
struct node * temp,* new;
temp=start;
new=create_ll();
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=new;
new->next=NULL;
return start;
}
struct node * delete_beg(struct node * start)
{
struct node * temp;
temp=start;
start=start->next;;
free(temp);
return start;
}
struct node * delete_pos(struct node * start)
{
struct node * temp,* pre;
int i,m;
temp=start;
printf(“\nenter the position”);
scanf(“%d”,&m);
for(i=0;inext;
}
pre->next=temp->next;
free(temp);
return start;
}
struct node * delete_end(struct node * start)
{
struct node * temp,*pre;
temp=start;
while(temp->next!=NULL)
{
pre=temp;
temp=temp->next;
}
free(temp);
pre->next=NULL;
return start;

}

Posted in Data Structures with C | Leave a comment