#include
#include
struct del
{
int number;
struct node *link;
};
typedef struct del node;
/*struct node *head;
struct node *new;
struct node *n1;
s
truct node *key;*/
void main()
{
node *find(node *p,int a);
int key;
node *n1;
node *head;
node *new;
node *p;
printf("ENTER THE NODE TO BE DELETED\n");
scanf("%d",&key);
if(hea
d->number == key)
{
new = (node*)malloc(sizeof(node));
p = head->link;
free(head);
head = p;
}
else
{
n1 = find(head,key);
if(n1 == NULL)
printf("NODE IS NOT FOUND\m");
else
{
p = n1->link->link;
free(n1->link);
n1->link = p;
}
}
}
node *find(node *list,int key)
{
if(list->link->number == key)
return list;
else
if(list->link->link == NULL)
return NULL;
else
find(list->link,key);
}
ShoutBox
Blog Archive
-
▼
2010
(22)
-
▼
January
(22)
- Linklist Node delete program in C
- Link List program in c
- Assembler program in C
- Accessing array in C using pipe
- Fork IPC program in C
- Executing another program in C
- Time program in C
- Sorting Program in C using fork and pipe
- Use of vfork in Unix C program
- Fork and Wait in Unix IPC C program
- Pipes in Unix IPC
- Complete sum program in Unix IPC
- Sort program in C using Unix IPC fork and pipe
- Shared memory in Unix C program
- Sum of N numbers program in C using Fork and Pipe IPC
- Inter process communication with fork and pipe
- Fork and Pipe program in C
- Fork with Pipe Program in C
- Another Fork program in C
- Simple Fork Program in Linux/Unix C
- Recursive File System Search Program in C
- Assembler Program in C
-
▼
January
(22)
Join With Me...
#include
#include
struct node
{
int number;
struct node *link;
};
struct node *head;
//struct node *next;
//struct node *prev;
//struct node *key;
void main()
{
node *find(node *p,int a);
int key;
node *n1;
node *p;
printf("ENTER THE NODE TO BE DELETED\n");
scanf("%d",&key);
if(head->number == key)
{
p = head->link;
free(head);
head = p;
}
else
{
n1 = find(head,key);
if(n1 == NULL)
printf("NODE IS NOT FOUND\m");
else
{
p = n1->link->link;
free(n1->link);
n1->link = p;
}
}
}
/* if(first == NULL)
printf("UNDERVLOW\n");
else
{
temp = first;
first = (struct node*)malloc(sizeof(struct node));
while(temp != key && temp->link !=NULL)
{
prev = temp;
temp = temp->link;
if(temp != key)
printf("NODE IS NOT FOUND\n");
else
{
if(key == first)
first = first->link;
else
prev->link = key->link;
key->link = avail;
avail = key;
}
}
}
} */
#include
#include
#include
void push(char [], int *, char [], int *);
char pop(char [], int *);
void push1(char, int *, char [], int *);
void main()
{
int i=0,top=-1,k=1,j,n;
char str[30],stack[20],lhs,rhs,ch;
clrscr();
printf("Enter the postfix expression: ");
scanf("%[^\n]s",str);
j = strlen(str);
str[j] = '#';
while(str[i] != '#')
{
if(isalpha(str[i]))
push(str,&i,stack,&top);
else
{
rhs = pop(stack,&top);
lhs = pop(stack,&top);
j = lhs;
n = rhs;
if(j >= 0 && j <= 9)
printf("LOD T%d\n",lhs);
else
printf("LOD %c\n",lhs);
if(n >= 0 && n <= 9)
{
switch(str[i])
{
case '+':
printf("ADD T%d\n",rhs);
break;
case '-':
printf("SUB T%d\n",rhs);
break;
case '*':
printf("MUL T%d\n",rhs);
break;
case '/':
printf("DIV T%d\n",rhs);
break;
}
}
else
{
switch(str[i])
{
case '+':
printf("ADD %c\n",rhs);
break;
case '-':
printf("SUB %c\n",rhs);
break;
case '*':
printf("MUL %c\n",rhs);
break;
case '/':
printf("DIV %c\n",rhs);
break;
}
}
ch = (char)k++;
printf("STO T%d\n",ch);
push1(ch,&i,stack,&top);
}
}
getch();
}
void push(char str[], int *i, char stack[], int *top)
{
(*top)++;
stack[*top] = str[(*i)++];
}
char pop(char stack[], int *top)
{
return stack[(*top)--];
}
void push1(char ch, int *i, char stack[], int *top)
{
(*top)++; (*i)++;
stack[*top] = ch;
}
#include
main()
{
int p1[2],p2[2],i=1,t=100,t1,res=0;
int arr[]={1,2,3,4,5,6,7,8,9,10};
int pro;
printf("RESULT : %d\n",i);
pipe(p1);
pro=fork();
if(pro==0)
{
printf("RESULT(T) : %d\n",i);
read(p1[0],t1,2);
write(i,t1,2);
printf("AFTER %d",i);
}
else
{
write(p1[1],t,2);
}
}
main()
{
int a[2];
int b[6]={1,2,3,4,5,6};
int p,tem1=0,tem2=0,i,j;
{
p=fork();
if(p==0)
{
for(j=0;j<6;j+=2)
printf("%d \n ", b[j]);
}
else
{
for(j=1;j<6;j+=2)
printf("%d \n ", b[j]);
}
}
printf("%d %d",tem1, tem2);
}
#include
#include
#include
void main(void)
{
int MAXLINE = 1024;
char buf[MAXLINE];
pid_t pid;
int status;
printf("%%");
while(fgets(buf,MAXLINE,stdin)!=NULL)
{
buf[strlen(buf)-1]=0;
if(pid=fork()<0)
err_sys("FORK ERROR");
else if(pid==0)
{
execlp(buf,buf,(char *)0);
err_ret("Couldn't Execute : %s",buf);
exit(127);
}
if((pid=waitpid(pid,&status,0))<0)
err_sys("Wait Pid Error");
printf("%%");
}
exit(0);
}
#include
#include
int main()
{
clock_t st,end;
long i,j,t;
st=clock();
for(i=0;i<10000L;i++)
for (j=0;j<50000L;j++)
t=0;
end=clock();
printf("\nSTARTING CLOCK: %lf",(double)st);
printf("\nEnding Clock : %lf",(double)end);
printf("\n%lf",(double)((end-st)/CLK_TCK));
return 0;
}
*/
#include
#include
main()
{
clock_t st,en;
int arr[10000],*ptr=arr,n,t;
float fir[5],sec[5],res;
unsigned long i,j;
for(t=0;t<5;t++)
{
st=clock();
for(j=0;j<10000L;j++)
for(i=0;i<10000;i++)
{
arr[i]=1;
}
en =clock();
printf("\nFIRST : %lf\n",fir[t]=(en-st)/CLK_TCK);
st=clock();
for(j=0;j<10000L;j++)
for(i=0;i<10000;i++)
{
*(ptr+i)=1;
}
en =clock();
printf("SECOND: %lf",sec[t]=(en-st)/CLK_TCK);
printf("\nDIFFERENCE : %lf\n",*(fir+t)-*(sec+t));
}
for(t=0;t<5;t++)
res=res+*(fir+t)+*(sec+t);
printf("\nTOTAL TIME IS : %lf\n",res);
res=0;
for(t=0;t<5;t++)
res=res+(*(fir+t)-*(sec+t));
printf("\nTOTAL TIME SAVE IS :%lf\n",res);
printf("\n\nEND");
return 0;
}
main()
{
void sort(int *,int);
int n,arr[10],i;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter Elements One By One\n");
for(i=0;i
scanf("%d",(arr+i));
sort(arr,n);
}
void sort(int *s,int n)
{
int a[2],i=0,b[2],c[2],temp=0;
int p,sec=0,j,fir=0;
int max=*(s+i);
if (n%2)
*(s+n)=0;
pipe(a);
pipe(b);
p=fork();
{
for(i=0;i
if(p>0)
{
if(i==0)
max=*(s+i);
write(a[1],&max,1);
read(b[0],&max,1);
if(max<*(s+i))
max=*(s+i);
}
else
{
sec=*(s+i+1);
read(a[0],&max,1);
if(max
max=sec;
write(b[1],&max,1);
}
}
printf("\nMAXIMUM IS :%d",max);
}
#include
int glob=6;
main()
{
int var,pid;
var=88;
printf(" Before vfork \n");
if((pid=vfork())<0)
printf("Vfork error \n");
else
if(pid>0);
else
{
glob++;
var++;
//_exit(0);
//sleep(2);
}
printf(" Pid=%d,glob=%d,var=%d\n",getpid(),glob,var);
exit(0);
}
#include
#include
//#include "ourhdr.h"
main()
{
int pid , status;
if((pid=fork()<0))
printf("fork error \n");
else if(pid==0)
exit(7);
if(wait(&status)!=pid)
printf("wait error \n");
_exit(status);
if((pid=fork()<0))
printf("fork error \n");
else if(pid==0)
abort();
if(wait(&status)!=pid)
printf("wait error \n");
_exit(status);
if((pid=fork()<0))
printf("Fork error \n");
else if(pid==0)
status/=0;
if(wait(&status)!=pid)
printf(" Wait error \n");
_exit(status);
exit(0);
}
#include
main()
{
clock_t st,en;
int a[2],i,b[2],c[2],s[]={1,2,3,4,5,6,7,8,9,10},temp=0;
int p,res=0,res1=0,n;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter All Elements One By One\n");
for(i=0;i
scanf("%d",(s+i));
//st=clock();
//printf("\nSTART IS :%d",st);
if(n%2==1)
{
n++;
*(s+i)=0;
}
pipe(a);
pipe(b);
p=fork();
for(i=0;i
if(p>0)
{
write(a[1],(s+i),1);
read(b[0],&temp,1);
res=res+temp;
}
else
{
read(a[0],&res1,1);
res=*(s+i+1)+res1;
write(b[1],&res,1);
}
printf("\nRES :%d",res);
en=clock();
printf("\nTOTAL TIME IS : %d ",(en-st));
}
main()
{
void sum(int);
int n;
printf("Enter The Total Elements\n");
scanf("%d",&n);
sum(n);
}
void sum(int n)
{
int a[2],i,b[2],c[2],s[1000],temp=0;
int p,res=0,res1=0;
for(i=0;i
*(s+i)=i+1;
if(n%2==1)
{
n++;
*(s+i)=0;
}
pipe(a);
pipe(b);
p=fork();
for(i=0;i
if(p>0)
{
write(a[1],(s+i),1);
read(b[0],&temp,1);
res=res+temp;
}
else
{
read(a[0],&res1,1);
res=*(s+i+1)+res1;
write(b[1],&res,1);
}
printf("\rRES :%d",res);
}
main()
{
void sort(int *,int);
int n,arr[10],i;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter Elements One By One\n");
for(i=0;i
scanf("%d",(arr+i));
sort(arr,n);
}
void sort(int *s,int n)
{
int a[2],i=0,b[2],c[2],temp=0;
int p,sec=0,j,fir=0;
int max=*(s+i);
if (n%2)
*(s+n)=0;
pipe(a);
pipe(b);
p=fork();
{
for(i=0;i
if(p>0)
{
write(a[1],&max,1);
read(b[0],&max,1);
if(max<*(s+i))
max=*(s+i);
printf("\nCHILD: %d ",max);
}
else
{
sec=*(s+i+1);
read(a[0],&max,1);
if(max
max=sec;
write(b[1],&max,1);
printf("\nPARENT: %d",max);
}
}
printf("\nMAXIMUM IS :%d SEC: %d",max,sec);
}
#include
main()
{
int x,y;
struct mot
{
int a,b;
char name[20];
}*ms;
x=shmget((key_t)2006,4096,0666|IPC_CREAT);
if(x>0)
printf("SHM created");
else
printf("Error");
shmat(struct mot *,)
main()
{
int a[2],i,b[2],c[2],s[]={1,2,3,4,5,6,7,8,9,10},temp=0;
int p,res=0,res1=0,n;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter All Elements One By One\n");
for(i=0;i
scanf("%d",(s+i));
//printf("%s",line);
pipe(a);
pipe(b);
p=fork();
if(n%2==1)
{
n++;
*(s+i)=0;
}
for(i=0;i
{
if(p>0)
{
//printf("NO IS %d ",i);
write(a[1],(s+i),1);
read(b[0],&temp,1);
res=res+temp;
}
else
{
//printf("NO IN @ IS: %d ",i);
read(a[0],&res1,1);
res=*(s+i+1)+res1;
write(b[1],&res,1);
//printf("TEMP VAL :%d ",res);
}
//system("sleep 1");
}
printf("RES :%d",res);
exit(1);
}
main()
{
int a[2];
int p,i;
pipe(a);
p=fork();
if(p>0)
{
write(a[1],10,2);
}
else
{
read(a[0],i,2);
printf("%d",i);
}
}
#include
main()
{
int p1[2],p2[2],i=1,t=100,t1,res=0;
int arr[]={1,2,3,4,5,6,7,8,9,10};
int pro;
printf("RESULT : %d\n",i);
pipe(p1);
pro=fork();
if(pro==0)
{
printf("RESULT(T) : %d\n",i);
read(p1[0],t1,2);
write(i,t1,2);
printf("AFTER %d",i);
}
else
{
write(p1[1],t,2);
}
}
main()
{
int a[2],i=0;
char line[26]="prasath",arun[26]="abcdefghijklmnopqrstuvwxyz";
int p;
//printf("%s",line);
pipe(a);
p=fork();
{
//for(i=0;i<27;)
if(p>0)
{
write(a[1],arun[0],1);
}
else
{
read(a[0],line[0],6);
}
printf("%s",line);
}
exit(0);
}
main()
{
int a[2],i,b[2];
char line[11]="abcdefghij",test[11]="1234567890";
int p;
//printf("%s",line);
pipe(a);
pipe(b);
{
p=fork();
for(i=0;i<11;i+=2)
{
if(p>0)
{
//printf("NO IS %d ",i);
write(a[1],test+i,1);
read(b[0],line+i+1,1);
}
else
{
//printf("NO IN @ IS: %d ",i+1);
read(a[0],line+i,1);
write(b[1],test+i+1,1);
}
system("sleep 1");
printf("%s\n",line);
}
}
exit(0);
}
#include
int glob=6;
char buf[]="a write to stdout\n";
main()
{
int var;
int pid;
var=88;
printf("Before Fork\n");
if((pid=fork())<0)
printf("fork Error\n");
else if(pid==0)
{
glob++;
var++;
} else
printf("\nPID= %d ,GLOB = %d,VAR = %d\n",getpid(),glob,var);
exit(0);
}
#include
#define MAX 500
char *sta[650],temp[MAXPATH];
struct ffblk ffblk;
unsigned long file,dir;
int done,pos=-1;
FILE *fp;
char * pop(void);
void push(char *);
void main()
{
char buffer[MAXPATH];
void find(char *);
fp=fopen("c:/t.txt","wb");
clrscr();
puts("Enter The Dirname (Ex: F:/fir/)");
scanf("%s",buffer);
find(buffer);
getch();
}
void find(char *dirname)
{
char temp[MAXPATH],temp1[MAXPATH];
int t,i;
if(!strcmp(dirname,NULL) || *dirname==NULL)
{
printf("\nSuccess!!!");
printf("\nFILE: %lu \nDIRE: %lu\n",file,dir);
getch();
exit(0);
}
strcpy(temp,dirname);
strcat(temp,"*.*");
t=strlen(dirname);
fwrite(dirname,t,1,fp);
fputc('\n',fp);
for(i=0;i
fputc('*',fp);
fputc('\n',fp);
done=findfirst(temp,&ffblk,FA_DIREC);
while(!done)
{
strcpy(temp1,dirname);
if(ffblk.ff_attrib==FA_DIREC)
{
if(*ffblk.ff_name!='.')
{
dir++;
strcat(temp1,ffblk.ff_name);
strcat(temp1,"/");
fwrite(ffblk.ff_name,sizeof(ffblk.ff_name),1,fp);
fwrite("\t
push(temp1);
*temp1='\0';
}
}
else
{
file++;
fwrite(ffblk.ff_name,sizeof(ffblk.ff_name),1,fp);
fputc('\n',fp);
}
done=findnext(&ffblk);
}
find(pop());
}
void push(char *a)
{
if(pos>=MAX)
puts("PUSH ERROR");
else
{
*(sta+ ++pos)=(char *)malloc(strlen(a)+1);
strcpy(sta[pos],a);
//printf("PUSH: %s\n",*(sta+pos));
}
}
char * pop(void)
{
if(pos==-1)
return("\0");
else
{
strcpy(temp,*(sta+pos));
free(*(sta+pos--));
//printf("POP: %s\n",temp);
return(temp);
}
}