Advertisement
Nabil-Ahmed

Untitled

Jul 26th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. //wap to convert a given string into sentence case//
  2. #include <stdio.h>
  3.  
  4. int StrToSentence(char * str)
  5. {
  6.     int len=0,i=0;
  7.  
  8.     len = strlen(str);
  9.  
  10.     for(i=0;i<len;i++)
  11.     {
  12.         if( (i==0) && (str[i]>='a' && str[i]<='z'))
  13.         {
  14.             str[i] = str[i] - 32;
  15.         }
  16.         else if(str[i]=='.')
  17.         {
  18.             if(str[i+1] == ' ')
  19.             {
  20.                 if(str[i+2]>='a' && str[i+2]<='z')
  21.                 {
  22.                     str[i+2] = str[i+2] - 32;
  23.                 }
  24.             }
  25.             else
  26.             {
  27.                 if(str[i+1]>='a' && str[i+1]<='z')
  28.                 {
  29.                     str[i+1] = str[i+1] - 32;
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     char str[100]={0};
  40.     int len=0,i=0,j=0,k=0;
  41.  
  42.     printf("\nEnter string : ");
  43.     gets(str);
  44.  
  45.  
  46.     StrToSentence(str);
  47.  
  48.     printf("Final string is : %s",str);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement