Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

10 February 2022

Function - strcmp()

 


#include<stdio.h>
#include<string.h>
 
int main()
{
    char *name = "Nandu";
    char *name1 = "Chandu";

    int value = strcmp(name, name1);
    printf("Now the value is %d", value);

    // This function is used to compare two strings.
    // It returns 0 : if strings are equal.
    // Negative Value : If first string's missmatching character's
    // ASCII value is not greater than sencond string's corresponding
    // mismatching character.
    // It returns positive value otherwise...

return 0;
}

OUTPUT-->

Now the value is 1

Function - strcat()

 


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

int main()
{
    char name[20] = "Nandkishor ";
    char *surname = "Rawool";

    strcat(name, surname);  
   
    //This function is used to concatenate two strings
    // This function does not add
    // space in between two string
   
    printf("Now the name is %s", name);
 
return 0;
}

OUTPUT--->

Now the name is Nandkishor Rawool

Function - strcpy()

 


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

int main()
{
    char *st = "Nandkishor";

    char name[15];

    strcpy(name,st);    //This function is used to copy first string into second
                        // or vice versa

    printf("Now the name is %s", name);
 
return 0;
}

OUTPUT--->

Now the name is Nandkishor

Function - strlen()



 #include<stdio.h>
#include<string.h>
 
int main()
{
    char *name = "Nandkishor";
    int a = strlen(name);
    printf("The lenght of string name is %d", a);

    // This function is used to print length of string...
 
return 0;
}

OUTPUT-->

The lenght of string name is 10

Function - puts()


  
#include<stdio.h>

int main()
{
    char name[50];
    printf("Enter your name : ");
    gets(name);
    puts(name);
   
   //puts is used to print without using printf function
 
return 0;
}

OUTPUT-->

Enter your name : Nandkishor Rawool. Nandkishor Rawool.

Function - gets()



#include<stdio.h>

int main()
{
    char name[50];
    printf("Enter your name : ");
    gets(name);

// This function is used to take
// multiple string at a time

    printf("Your name is %s", name);
 
return 0;
}

OUTPUT-->

Enter your name : Nandkishor Rawool Your name is Nandkishor Rawool

String User Input



#include<stdio.h>
 
int main()
{
    char str[40];
    printf("Enter your name : ");
    scanf("%s", str);
    printf("Your name is : %s", str);
 
return 0;
}

OUTPUT-->

Enter your name : Nandkishor Your name is : Nandkishor