Prog05.c

 /*	
Practical Assignment : 5
Name    : Divyen K Patel Roll No:24 MCA-4
Program : 5
To count the total no of characters in one or more
character strings by any parallel technique.
*/

# 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

*/

Project Homepage: