Showing posts with label library. Show all posts
Showing posts with label library. Show all posts

Friday, 12 August 2016

strrev: Reversing the string using library function

String: strrev(string)

Reversing the string using library function


#include<stdio.h>          
#include<string.h>
main()
{
                char s[60];
                printf("\nEnter string:\t");
                gets(s);
                printf("\nReversed string is:  %s", strrev(s));
}
Output:
Enter string:   Hello How Are You
Reversed string is:  uoY erA woH olleH

strncpy: Copy specified number of characters from one string to another string using library function

String: strncpy(dest, source, n)


Copy specified number of characters from one string to another string using library function


#include<string.h>
main()
{
                char s[60], d[60]="\0";
                printf("\nSource string:\t");
                gets(s);
                strncpy(d, s, 5);
                printf("\nDestination string: %s", d);
}
Output:
Source string:  Hii How Are you

Destination string: Hii H

strcpy: Copy one string to another string using library function

String: strcpy(dest, source)

Copy one string to another string using library function


#include<stdio.h>
#include<string.h>
main()
{
                char s[60], d[60]="\0";
                printf("\nSource string:\t");
                gets(s);
                strcpy(d, s);
                printf("\nDestination string: %s", d);
}
Output:
Source string:  Hii How Are you
Destination string: Hii How Are you

strupr: Convert from Lower case to Upper case using Library function

String: strupr(string)

Convert from Lower case to Upper case using Library function


#include<stdio.h>
#include<string.h>
main()
{
                char s[60];
                printf("\nEnter string:\t");
                gets(s);
                printf("\nString in uppercase: %s", strupr(s));
}

Output:
Enter string:   Hello How Are You
String in uppercase: HELLO HOW ARE YOU

strlwr: Convert from Upper case to Lower case using Library function

String: strlwr(string)

Convert from Upper case to Lower case using Library function


#include<stdio.h>
#include<string.h>
main()
{
                char s[60];
                printf("\nEnter string:\t");
                gets(s);
                printf("\nString in lowercase: %s", strlwr(s));
}
Output:
Enter string:   Hello How Are You
String in lowercase:  hello  how are you

Thursday, 11 August 2016

strlen: Length of the string using library function

String: strlen(string)

Length of the string using library function


#include<stdio.h>          
#include<string.h>
main()
{
                char s[60];
                printf("\nEnter string:\t");
                gets(s);
                printf("\nLength of string is: %d", strlen(s));
}

Output:
Enter string:   Hello How Are You
Length of string is: 17