Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING

Posted By: Raimundo Fischer     Category: C Programming     Views: 4464

PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING.

Code for PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING in C Programming

#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;
        elseif(*(final+i)==1)
        {
            flg=1;
            break;
        }
    }
    if(flg==0)
        printf("\n Strings are equal");
    elseif(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
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING Or get search suggestion and latest updates.

Raimundo Fischer
Raimundo Fischer author of PROGRAM TO COMPARE TWO STRINGS USING LOOP SPLITTING is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!