Guest User

Untitled

a guest
Oct 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. //***************************************************//
  2.  
  3. PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include \"headfork.h\"
  8. #include \"headsem.h\"
  9. #include \"headshr.h\"
  10.  
  11. main()
  12. {
  13. int i,nprc,id,shmid1,shmid2,shmid3,*final,flg=0;
  14. char *s1,*s2;
  15.  
  16. s1=(char *)shared(sizeof(char)*10,&shmid1);
  17. s2=(char *)shared(sizeof(char)*10,&shmid2);
  18. final=(int *)shared(sizeof(int)*5,&shmid3);
  19.  
  20.  
  21. for(i=0;i<10;i++)
  22. {
  23. *(s1+i)=\'\\0\';
  24. *(s2+i)=\'\\0\';
  25. }
  26.  
  27. printf(\"Enter first string : \");
  28. scanf(\"%s\",s1);
  29.  
  30. printf(\"\\nEnter second string : \");
  31. scanf(\"%s\",s2);
  32.  
  33. printf(\"\\nEnter the no.of proc: \");
  34. scanf(\"%d\",&nprc);
  35.  
  36. id=p_fork(nprc);
  37. *(final+id)=1;
  38.  
  39. for(i=id;*(s1+i)!=\'\\0\' || *(s2+i)!=\'\\0\';i+=nprc)
  40. {
  41. //if(strcomp(*(s1+i),*(s2+i))==0)
  42. if(*(s1+i)=*(s2+i))
  43. *(final+id)=0;
  44. else
  45. {
  46. *(final+id)=1;
  47. break;
  48. }
  49. }
  50.  
  51. p_join(nprc,id);
  52.  
  53. for(i=0;i<nprc;i++)
  54. {
  55. if(*(final+i)==0)
  56. flg=0;
  57. else if(*(final+i)==1)
  58. {
  59. flg=1;
  60. break;
  61. }
  62. }
  63. if(flg==0)
  64. printf(\"\\n Strings are equal\");
  65. else if(flg==1)
  66. printf(\"\\n Strings are not equal\");
  67. }
  68.  
  69. OUTPUT
  70.  
  71. knoppix@ttyp0[pp]$ cc comp_str_lps.c
  72. knoppix@ttyp0[pp]$ ./a.out
  73. Enter first string : college
  74.  
  75. Enter second string : college
  76.  
  77. Enter the no.of proc: 3
  78.  
  79. Strings are equal
  80.  
  81. knoppix@ttyp0[pp]$ cc comp_str_lps.c
  82. knoppix@ttyp0[pp]$ ./a.out
  83. Enter first string : college
  84.  
  85. Enter second string : vasad
  86.  
  87. Enter the no.of proc: 3
  88.  
  89. Strings are not equal
Add Comment
Please, Sign In to add comment