#include <stdio.h>
#include <conio.h>
#include <string.h> /*library for string manipulation functions*/
void main()
{
char s1[30],s2[30];
char s3[]="BHUJEL";
printf("Enter a string: ");
gets(s1); /*Function to read string from user*/
printf("Enter another string: ");
gets(s2); /*scanf("%s",s2); main difference is: this scanf cannot take
string after white space*/
printf("First string is ");
puts(s1); /*Function to display string*/
printf("Second string is %s",s2);
printf("\n");
printf("Length of 1st string is %d",strlen(s1));
int l=strlen(s2); /*finds the length of string s2*/
printf("\nLength of 2nd string is %d",l);
printf("\n");
printf("Reverse of 1st string is %s",strrev(s1)); /*reverses the string s1*/
printf("\n");
strupr(s1); /*makes uppercase to string s1*/
puts(s1);
strlwr(s2); /*makes lowercase to sstring s2*/
puts(s2);
strrev(s1);
strlwr(s1);
puts(s1);
if(strcmp(s1,s2)==0) /*compares ASCII values of two strings and outputs
integer value*/
printf("Equal");
else
printf("%d",strcmp(s1,s2));
printf("\n");
strcat(s1,s2); /*concatenates (joins) two strings as s1<-s1+s2 */
puts(s1);
strcpy(s2,s1); /*copies one string to another as s1<-s1 */
puts(s2);
strcat(s2,s3);
puts(s2);
getch();
}
OUTPUT:
No comments:
Post a Comment