Logo 
Search:

C Programming Articles

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

Program to count the total no of characters in one or more character strings by any parallel technique

Posted By: Adelle Fischer     Category: C Programming     Views: 1802

To count the total no of characters in one or more character strings by any parallel technique.

Code for Program to count the total no of characters in one or more character strings by any parallel technique in C Programming

# include <stdio.h>
# include <pthread.h>

int MainCharCount=0;
int ThreadCharCount=0;
char *str;
void *FunCountChar(void *);

int main()
{    
    int iCount;
    int TotalCount=0;
    pthread_t tid;
    
    str=(char *)malloc(sizeof(char)*100);
    for(iCount=0;iCount<100;iCount++)
    {
        str[iCount]='\0';
    }
    
    str="Divyen k Patel\0";
    
    pthread_create(&tid,NULL,FunCountChar,NULL);    
    
    iCount=0;
    
    while(str[iCount]!='\0')
    {
        if(str[iCount]!=' ')
        {
            MainCharCount++;
        }
        iCount=iCount+2;
    }
    
    pthread_join(tid,NULL);
    
    TotalCount=MainCharCount + ThreadCharCount;
    printf("String is: %s\n",str);
    printf("Total Number of Character: %d\n",TotalCount);        
    return 0;
}

void *FunCountChar(void *arg)
{        
    int iCount=1;    
    while(str[iCount]!='\0')
    {
        if(str[iCount]!=' ')
        {
            ThreadCharCount++;
        }
        iCount=iCount+2;        
    }    
    pthread_exit(NULL);    
}

/* Output

[divyen@localhost pp-tw5]$ cc -o Prog05 -lpthread Prog05.c
[divyen@localhost pp-tw5]$ ./Prog05
String is: Divyen k Patel
Total Number of Character: 12

*/
  
Share: 



Adelle Fischer
Adelle Fischer author of Program to count the total no of characters in one or more character strings by any parallel technique 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!