Search C Program

String to lower case - STRLWR

/* STRING TO LOWER CASE - STRLWR */

#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;
 }
 
 printf("String in lower case is: %s",str);

 return 0;
}
 

2 comments:

  1. #include
    #include
    void main()
    {
    printf("enter character");
    gets(s);
    for(i=0;s[i]!=NULL;i++)
    if(s[i]>=65&&s[i]<=90)
    s[i]=s[i]+32;
    else
    if(s[i]>=97&&s[i]<=122)
    s[i]=s[i]-32;
    puts(s);
    getch();
    }

    OUTPUT :->

    Enter character :-> I AM indian

    OUTPUT :-> i am INDIAN

    ReplyDelete