Search This Blog

Wednesday, October 28, 2015

count all repeated character in a given string.

1:  #include <stdio.h>  
2:  main()  
3:  {  
4:    char str[100] = "akjdl**&%$*(*(^%kdfja";  
5:    int arr[255] = {0}; // 255 for max ascii value  
6:    int i = 0;  
7:    for(i=0;str[i] != '\0';i++)  
8:      arr[str[i]]++;  
9:    for(i=0;i<255;i++)  
10:    {  
11:      if ( arr[i] >= 1)  
12:        printf("%c is repeated %d times\n",i,arr[i]);  
13:    }  
14:  }  

No comments:

Post a Comment