Search C Program | nimishsoft@gmail.com

Toggle case of string

/* TOGGLE CASE OF STRING */

#include<stdio.h>

int main()
{
 char str[100];
 int i;
 printf("Please enter a string: ");

 // gets(str); 
 // fgets is a better option over gets to read multiword string .

 fgets(str, 100, stdin);
 
 // Following can be added for extra precaution for '\n' character
 // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL;

 for(i=0;str[i]!=NULL;i++)
 {
  if(str[i]>='A'&&str[i]<='Z')
   str[i]+=32;
  else if(str[i]>='a'&&str[i]<='z')
   str[i]-=32;
 }
 
 printf("String in toggle case is: %s",str);

 return 0;
}

12 comments:

  1. Replies
    1. Attention everyone, the file provided above is not working. I have been looking for the working file and finally found it.



      ✔️Click Here To Download http://gestyy.com/e0GAyS
      ✔️Click Here To Download

      ✔️Click Here To Download http://exe.io/XONVsO6l

      ✔️Click Here To Download


      ✔️Click Here To Download
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .

      .

      .
      .

      .

      .
      .
      .
      .

      Mn.
      ..

      .
      .
      .
      ..
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      ..
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .cxx
      .sdcccxxx

      Delete
  2. Great job n i have been following your .n i want reverse the words of a string like
    input:- i am a boy.
    output:- boy. a am i
    kindly send me the answer of it

    ReplyDelete
    Replies
    1. http://cbasicprogram.blogspot.in/2012/05/string-reverse-strrev.html

      Delete
  3. what is the use of str[i] != NULL....i don't know....

    ReplyDelete
  4. What is code for this program?,if i input SK JAHANGIR ALAM and output wil be S.J,ALAM

    ReplyDelete
  5. Replies
    1. It will increase the ASCII value of the character . As the difference of ASCII value between any lowercase character and uppercase character is 32 ,we add 32 which makes uppercase character to its respective lowercase. A=65, a=97 => A+32='a' .so A became 'a' by adding 32 and vice versa in else part.

      Delete
  6. this code needs lot of memory locations can u plz tell me a fast and reliable code

    ReplyDelete
    Replies
    1. if(str[i]>='A'&&str[i]<='Z')
      str[i]=str[i]+'a'-'A';

      elseif(str[i]>='a'&&str[i]<='z')
      str[i]+'A'-'a';


      Delete