strlwr, strupr in c

stwlwr in c

#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>

main()
{
char string[] = "strupr in c";

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

return 0;
}

Change string to upper case without strupr

#include<stdio.h>

void upperString(char*);

main()
{
char string[100];

printf("Enter a string to convert it into upper case\n");
gets(string);

upperString(string);

printf("Entered string in upper case is \"%s\"\n", string);

return 0;
}

void upperString(char *string)
{
while(*string)
{
if ( *string >= 'a' && *string <= 'z' )
{
*string = *string - 32;
}
string++;
}
}

Change string to lower case without strlwr

#include<stdio.h>

void lowerString(char*);

main()
{
char string[100];

printf("Enter a string to convert it into lower case\n");
gets(string);

lowerString(string);

printf("Entered string in lower case is \"%s\"\n", string);

return 0;
}

void lowerString(char *string)
{
while(*string)
{
if ( *string >= 'A' && *string <= 'Z' )
{
*string = *string + 32;
}
string++;
}
}

Post a Comment

0 Comments