Logo 
Search:

C Programming Articles

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

Program for count number of digits in string

Posted By: Adalgar Fischer     Category: C Programming     Views: 3706

Program for count number of digits in string.

Code for Program for count number of digits in string in C Programming

#include <stdio.h>
#include "headfork.h"// included in attachment
#include "headsem.h"
#include "headshr.h"

main()
{
        int id,i,sid1,sid2,nprc;
        char *str;
        int *cnt,s,*lock;

        cnt=(int *)shared(sizeof(int)*2,&sid1);
    lock=(int *)shared(sizeof(int)*2,&sid2);

    str=(char *)malloc(20);

        for(i=0;i<20;i++)
                str[i]='\0';
    lock_init(lock);

        printf("Enter any String :");
        scanf("%s",str);
    
    printf("Enter no. of proc:");
        scanf("%d",&nprc);

        id=p_fork(nprc);
        s=0;

        for(i=id;*(str+i)!='\0';i+=nprc)
        {
                if(*(str+i)>=65 && *(str+i)<=90 || *(str+i)>=97 && *(str+i)<=122)
                        s=s+1;
        }

    locksem(lock);
    *cnt=*cnt+s;
    unlock(lock);
    
        p_join(nprc,id);

    printf("No. of characters are : %d",*cnt);
}
  
Share: 


Didn't find what you were looking for? Find more on Program for count number of digits in string Or get search suggestion and latest updates.

Adalgar Fischer
Adalgar Fischer author of Program for count number of digits in string 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!