Advertisement
apl-mhd

demoVersion2

Oct 29th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.     char str[50][50];
  5.  
  6. int wordCount(char name[50]){  /* count total word in a string*/
  7.  
  8.     int totalWord = 1, i=1;
  9.  
  10.  
  11.     while(name[i] != '\0'){
  12.  
  13.         if( name[i] == ' '){
  14.  
  15.             totalWord++;
  16.         }
  17.  
  18.         i++;
  19.     }
  20.  
  21.  
  22.     return totalWord;
  23.  
  24. }
  25.  
  26. /****************** charcter count in a string   ****************/
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. void copyString(char name[50], int size, int totalWord){ /* copy string in 2d char array reverse*/
  34.  
  35.     int i, j=0, temp, m=0;
  36.  
  37.     for(i = 0; i < totalWord; i++){
  38.  
  39.  
  40.             m = 0;
  41.         while(name[j] != '\0'){
  42.  
  43.                 str[i][m] =name[j];
  44.  
  45.                 j++;
  46.                 m++;
  47.  
  48.                 if(name[j-1] == ' ')
  49.                     break;
  50.         }
  51.  
  52.  
  53.     }
  54.  
  55.     printf("%s", str[0]);
  56.     printf("%s", str[1]);
  57.     printf("%s", str[2]);
  58.     printf("%s\n", str[3]);
  59.         printf("-------------------------------------------------\n");
  60.  
  61.  
  62.    // printf(" %c %c %c %c ", str[0][0], str[0][1], str[0][2], str[0][3]);
  63.  
  64. }
  65.  
  66.  
  67. /********************** count only charcter in a charter array **************************/
  68. int charcterCount(int i){
  69.  
  70.         int totalCharcter = 0, j = 0;
  71.  
  72.         while(str[i][j] != '\0'){
  73.  
  74.             if(str[i][j] >= 'A' && str[i][j] <= 'Z'){
  75.  
  76.                 totalCharcter++;
  77.             }
  78.  
  79.             j++;
  80.         }
  81.  
  82.         //printf("count %s \n", str[i]);
  83.  
  84.         printf(" %d = %d \n", i, totalCharcter-1 );
  85.  
  86.         return totalCharcter-1;
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /*********************** reverse *****************************************/
  97.  
  98. void  stringReverse(char twodString[50][50], int totalWord){
  99.  
  100.     int i , j, m, n ;
  101.     char temp;
  102.  
  103.  
  104.  
  105.     for(i = 0; i < totalWord; i++){
  106.  
  107.       charcterCount(i);
  108.  
  109.        n = strlen(twodString[i]) -1;
  110.        m = 0;
  111.  
  112.         while(m < n){
  113.  
  114.            temp = twodString[i][m];
  115.            twodString[i][m] = twodString[i][n];
  116.            twodString[i][n] = temp;
  117.  
  118.             m++;
  119.             n--;
  120.            }
  121.  
  122.         }
  123.  
  124.  
  125. //    printf("%s", str[0]);
  126. //    printf("%s", str[1]);
  127. //    printf("%s", str[2]);
  128. //    printf("%s\n", str[3]);
  129. //    printf("-------------------------------------------------\n");
  130.  
  131.  
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. int main(int argc, char *argv[])
  141. {
  142.  
  143.  
  144.  
  145.  
  146.     char name[80] = "NUR, REHTOM! REDRUM!!";
  147.  
  148.     int stringLength, totalWord;
  149.  
  150.     stringLength = strlen(name);
  151.  
  152.    totalWord = wordCount(name);
  153.  
  154.    printf("total %d \n", totalWord);
  155.  
  156.    copyString(name, stringLength, totalWord);
  157.  
  158.    stringReverse(str, totalWord);
  159.  
  160.  
  161.  
  162.     return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement