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

Program 22

The document presents a C program for string manipulation without using any library functions. It includes functionalities to find the length of a string, concatenate two strings, compare strings of the same length, search for a character in a string, and reverse a string. The program allows user interaction through a menu-driven interface to perform these operations.

Uploaded by

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

Program 22

The document presents a C program for string manipulation without using any library functions. It includes functionalities to find the length of a string, concatenate two strings, compare strings of the same length, search for a character in a string, and reverse a string. The program allows user interaction through a menu-driven interface to perform these operations.

Uploaded by

jhapushpam.work
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 22: WAP to do string manipulation without using any library

function for strings:


1) Length of the string.
2) Concatenate two strings.
3) Compare two strings of the same length.
4) Search a character in the string.
5) Reverse the string.

Code:
#include <stdio.h>
int len(char*);
void add(char*,char*);
void comp(char*,char*);
void search(char*,char);
void rev(char*);
void main(){
int choice,i;
char con;
char character;
char str1[] = "This is a Great Day";
char str2[] = "This is a Great Day";
char str3[] = "All is well";
do{
printf("String Manipulation Function \n ");
printf("[Link] of the String \n");
printf("[Link] two strings \n");
printf("[Link] Strings of Same Length \n");
printf("[Link] Character in the String \n");
printf("[Link] the String \n");
printf("Enter Choice : ");
scanf("%d",&choice);
switch(choice){
case 1:
printf("%d \n",len(str1));
break;
case 2:
add(str1,str3);
break;
case 3:
comp(str1,str2);
break;
case 4:
printf("Enter Character To be Searched : ");
fflush(stdin);
scanf("%c",&character);
search(str1,character);
break;
case 5:
rev(str1);
break;
default:
printf("Invalid Choice !!");
}
printf("Enter 1 to Continue : ");
fflush(stdin);
scanf("%d",&con);
}
while(con==1);
}
int len(char* str){
int i=0,count=0;
while (str[i] !='\0')
{
count++;
i++;
}
return count;
}
void add(char* str1,char* str2){
int i=0,j=0;
char str3[100];
while (str1[i] !='\0')
{
str3[j] = str1[i];
i++;
j++;
}
i = 0;
str3[j] = ' ';
while (str2[i] !='\0')
{
str3[j] = str2[i];
i++;
j++;
}
printf("\n The Concatenated String : %s \n",str3);
}
void comp(char* str1,char* str2){
int str1len,str2len,flag=0,i=0 ;
str1len = len(str1);
str2len = len(str2);
if(str1len==str2len){
while (str1[i] !='\0')
{
if(str1[i]==str2[i]){
flag = 1;
}
else {
flag = 0 ;
break;
}
i++;
}
}
else{
printf("IF Part Failed Strings are not Same Lenght \n!!");
}
if(flag==1){
printf("True \n");
}
else{
printf("False \n");
}
}
void search(char* str,char x){
int i=0,flag=0 ;
while (str[i] != '\0')
{
if(str[i]== x ){
printf("%c Character Found at %d index \n",x,i);
flag=1;
break;
}
i++;
}
if (flag == 0){
printf("Not Found !! \n");
}
}
void rev(char* str){
int strlen,i;
strlen = len(str);
for(i=strlen-1;i>=0;i--){
printf("%c",str[i]);
}
printf("\n");
}

OUTPUT:

You might also like