0% found this document useful (0 votes)
18 views5 pages

Exno 5

Watha poda punda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Exno 5

Watha poda punda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXNO:5 String Operations

Aim:

Procedure:

5.1 Program for copy one string to another string


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

int main() {
char str1[20] = "C programming";
char str2[20];
// copying str1 to str2
strcpy(str2, str1);
printf("Value of second string is: %s",str2);
return 0;
}

Output:
Value of second string: C programming
5.2 Program to find the length of the string

#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','\0'};
printf("Length of string a = %d \n",strlen(a));
printf("Length of string b = %d \n",strlen(b));

return 0;
}

Output:
Length of string a:7
Length of string b:7
5.3 Program for compare the two strings
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main() {
char str1[20] = "hello";
char str2[20] = "world";

int result = strcmp(str1, str2);


if (result == 0) {
printf("The strings are equal\n");
}
else if (result > 0) {
printf("%s is greater than %s\n", str1, str2);
}
else {
printf("%s is less than %s\n", str1, str2);
}
return 0;
}
Output:
hello is less than world

5.4 Program for concatenate two strings


#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Hello ";
char str2[] = "World!";
// Concatenate str2 to str1 (the result is stored in str1)
strcat(str1, str2);
// Print str1
printf("%s", str1);
return 0;}
}
Output:
Hello World!

Result:

You might also like