Tuesday, 28 October 2014

Basic String Handling Functions

Aim:
To demonstrate the string Handling Functions.

Program:
#include<stdio.h>
#inude<string.h>
void main ()
{
   char S1[50],S2[50];

puts("Enter first string:");
gets(S1);
puts("\nEntet second string:");
gets(S2);

printf("\nleangths of S1 is %d and S2 is %d.",strlen (S1),strlen (S2));

if( !strcmp(S1,S2) )
     printf("\ntwo strings are equal.");
else
     printf("\ntwo strings are not equal.");

strcat(S1,S2);
      printf("\n%s",S1);

strcpy( S1,"This is a test");
       printf("%s\n",S1);

if( strchr("hello",'e');
        printf("e is in hello\n");

if( strstr("hi these","hi");
        printf("found hi");
}

Output:
Enter first string: hello
Enter second string: hello
leangths of S1 is 5 and S2 is 5.
two strings are equal
hellohello
This is a test
e is in hello
found hi

No comments:

Post a Comment