Sunday, July 26, 2015

String_upper to lower and lower to upper case

#include <stdio.h>
#include <string.h>

int main ()
{
   int c = 0;
   char ch, s[1000];

   printf("Input a string\n");
   gets(s);

   for(c=0;s[c] != '\0';c++) {
      ch = s[c];
      if (ch >= 'A' && ch <= 'Z')
         s[c] = s[c] + 32;
      else if (ch >= 'a' && ch <= 'z')
         s[c] = s[c] - 32;

   }

   printf("%s\n", s);

   return 0;
}

No comments:

Post a Comment