Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************//
- PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING
- #include <stdio.h>
- #include <string.h>
- #include \"headfork.h\"
- #include \"headsem.h\"
- #include \"headshr.h\"
- main()
- {
- int i,nprc,id,shmid1,shmid2,shmid3,*final,flg=0;
- char *s1,*s2;
- s1=(char *)shared(sizeof(char)*10,&shmid1);
- s2=(char *)shared(sizeof(char)*10,&shmid2);
- final=(int *)shared(sizeof(int)*5,&shmid3);
- for(i=0;i<10;i++)
- {
- *(s1+i)=\'\\0\';
- *(s2+i)=\'\\0\';
- }
- printf(\"Enter first string : \");
- scanf(\"%s\",s1);
- printf(\"\\nEnter second string : \");
- scanf(\"%s\",s2);
- printf(\"\\nEnter the no.of proc: \");
- scanf(\"%d\",&nprc);
- id=p_fork(nprc);
- *(final+id)=1;
- for(i=id;*(s1+i)!=\'\\0\' || *(s2+i)!=\'\\0\';i+=nprc)
- {
- //if(strcomp(*(s1+i),*(s2+i))==0)
- if(*(s1+i)=*(s2+i))
- *(final+id)=0;
- else
- {
- *(final+id)=1;
- break;
- }
- }
- p_join(nprc,id);
- for(i=0;i<nprc;i++)
- {
- if(*(final+i)==0)
- flg=0;
- else if(*(final+i)==1)
- {
- flg=1;
- break;
- }
- }
- if(flg==0)
- printf(\"\\n Strings are equal\");
- else if(flg==1)
- printf(\"\\n Strings are not equal\");
- }
- OUTPUT
- knoppix@ttyp0[pp]$ cc comp_str_lps.c
- knoppix@ttyp0[pp]$ ./a.out
- Enter first string : college
- Enter second string : college
- Enter the no.of proc: 3
- Strings are equal
- knoppix@ttyp0[pp]$ cc comp_str_lps.c
- knoppix@ttyp0[pp]$ ./a.out
- Enter first string : college
- Enter second string : vasad
- Enter the no.of proc: 3
- Strings are not equal
Add Comment
Please, Sign In to add comment