Author Topic: strlwr, strupr in c  (Read 1115 times)

candy

  • Full Member
  • ***
  • Posts: 146
    • View Profile
strlwr, strupr in c
« on: November 12, 2013, 01:07:41 PM »
Here we will change string case with and without strlwr, strupr functions.

strlwr in c

Code: [Select]
#include <stdio.h>
#include <string.h>
 
int main()
{
    char string[] = "Strlwr in C";
 
    printf("%s\n",strlwr(string));
 
    return  0;
}
strupr in c
#include <stdio.h>
#include <string.h>
 
int main()
{
    char string[] = "strupr in c";
 
    printf("%s\n",strupr(string));
 
    return  0;
}

Change string to upper case without strupr

Code: [Select]
#include <stdio.h>
 
void upper_string(char*);
 
int main()
{
   char string[100];
 
   printf("Enter a string to convert it into upper case\n");
   gets(string);
 
   upper_string(string);
 
   printf("Entered string in upper case is \"%s\"\n", string);
 
   return 0;
}
 
void upper_string(char *string)
{
   while(*string)
   {
       if ( *string >= 'a' && *string <= 'z' )
       {
          *string = *string - 32;
       }
       string++;
   }
}

Change string to lower case without strlwr

Code: [Select]
#include <stdio.h>
 
void lower_string(char*);
 
int main()
{
   char string[100];
 
   printf("Enter a string to convert it into lower case\n");
   gets(string);
 
   lower_string(string);
 
   printf("Entered string in lower case is \"%s\"\n", string);
 
   return 0;
}
 
void lower_string(char *string)
{
   while(*string)
   {
      if ( *string >= 'A' && *string <= 'Z' )
      {
         *string = *string + 32;
      }
      string++;
   }
}

Engineer Forum

strlwr, strupr in c
« on: November 12, 2013, 01:07:41 PM »