Thursday, 6 September 2012

/* --- Program on Built-in Functions of Strings --- */


#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
    char str1[100],str2[100],str3[100];
    int i,j,m,n;

    clrscr();
    gotoxy(15,2);
    printf("Program on Built-in Functions of Strings \n");
    gotoxy(5,5);
    printf("Enter a String1 : ");
    gets(str1);
    gotoxy(5,7);
    printf("Enter a String2 : ");
    gets(str2);
    gotoxy(5,9);

/*    String Copying    */
    strcpy(str3,str1);
    printf("\n%s\n",str3);

/*    String Concatenation    */
    strcat(str3,str2);
    printf("\n%s\n",str3);

/*    String Comparison    */
    if (strcmp(str1,str2)==0)
        puts("\nEntered Strings are same");
    else if(strcmp(str1,str2)<0)
        printf("\n%s is Greater than %s\n",str1,str2);
         else
        printf("\n%s is Less than %s\n",str1,str2);

/*    String Length    */
    printf("\nThe No. of Characters in %s is %d\n",str1,strlen(str1));

/*    String Reverse    */
    strcpy(str3,str2);
    printf("\nThe String %s in reverse is %s\n",str3,strrev(str2));

/*    String set    */
    strset(str3,'$');
    printf("\n%s",str3);

    getch();
}

No comments:

Post a Comment