Program to Reverse a String
#include <stdio.h>
#include <string.h>
int main(){
char str[40]; // declare the size of character string
printf (" \n Enter a string to be reversed: ");
scanf ("%s", str);
// use strrev() function to reverse a string
printf (" \n After the reverse of a string: %s ", strrev(str));
return 0;
}
Program to Concatenate Two Strings
#include <stdio.h>
int main() {
char s1[100] = "VTU ", s2[] = "Updates";
int length, j;
// store length of s1 in the length variable
length = 0;
while (s1[length] != '\0') {
++length;
}
// concatenate s2 to s1
for (j = 0; s2[j] != '\0'; ++j, ++length) {
s1[length] = s2[j];
}
// terminating the s1 string
s1[length] = '\0';
printf("After concatenation: ");
puts(s1);
return 0;
}
Program to Compare Two Strings
#include <stdio.h>
#include<string.h>
int main()
{
char str1[50]; // declaration of char array
char str2[50]; // declaration of char array
int value; // declaration of integer variable
printf("Enter the first string : ");
scanf("%s",str1);
printf("Enter the second string : ");
scanf("%s",str2);
// comparing both the strings using strcmp() function
value = strcmp(str1,str2);
if(value == 0)
printf("strings are same");
else
printf("strings are not same");
return 0;
}