Using the string library functions.

#include <stdio.h>
#include <string.h>

int main(void)
{
char str1[80], str2[80];
int len;

printf("\nEnter a string : ");
gets(str1);

// copy the second string to the first string
strcpy(str2, str1);
printf("\nCopied string : %s", str2);

// find the length of the string
len = strlen(str2);
printf("\nLength of string : %d", len);

// concatenate the second string to the first string
strcat(str2, str1);
printf("\nConcatenated string : %s", str2);

// reverse the string
strrev(str2);
printf("\nReversed string : %s", str2);

printf("\nEnter a string to search : ");
gets(str1);

// search for an occurance of the second string in the first string
if(strstr(str2, str1))
{
printf("\n%s occurs in %s", str1, str2);
}

// compare the first string with the second string.
if(strcmp("AAAA","AAAA") == 0)
{
printf("\nBoth the strings are same");
}

if(strcmp("Goal","Good") < 0)
{
printf("\nThe first string occurs before the second string");
}

if(strcmp("Good","Goal") > 0)
{
printf("\nThe first string occurs after the second string");
}

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin