37. Write a program to find a character from given string.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[20],ch;
int i,f;
printf("Enter String: ");
gets(str);
printf("\nEnter Character to Search from String: ");
scanf("%c",&ch);
for(i=0;str[i]!='\0';i++)
{
if(ch==str[i])
{
f=0;
break;
}
else
f=1;
}
if(f==0)
printf("\n character is available");
else
printf("\n character is not available");
}
38. Write a program to replace a character in given string.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[20],ch1,ch2;
int i,f;
printf("Enter String: ");
gets(str);
printf("\nEnter Character to Replace: ");
ch1=getche();
printf("\nEnter Character with Replace: ");
scanf("%c",&ch2);
for(i=0;str[i]!='\0';i++)
{
if(ch1==str[i])
{
str[i]=ch2;
f=0;
break;
}
else
f=1;
}
if(f==0)
{
printf("\n character is Replaced");
printf("\n New string %s",str);
}
else
printf("\n character is not available to replace");
}
39. Write a program to delete a character in given string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[20],ch,str2[20];
int i,j=0;
printf("Enter String: ");
gets(str1);
printf("\nEnter Character to Delete: ");
scanf("%c",&ch);
for(i=0;str1[i]!='\0';i++)
{
if(ch!=str1[i])
{
str2[j]=str1[i];
j++;
}
}
str2[j]='\0';
strcpy(str1,str2);
printf("\n New string %s",str1);
}
#include<stdio.h>
#include<conio.h>
int main()
{
char str[20],ch;
int i,f;
printf("Enter String: ");
gets(str);
printf("\nEnter Character to Search from String: ");
scanf("%c",&ch);
for(i=0;str[i]!='\0';i++)
{
if(ch==str[i])
{
f=0;
break;
}
else
f=1;
}
if(f==0)
printf("\n character is available");
else
printf("\n character is not available");
}
38. Write a program to replace a character in given string.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[20],ch1,ch2;
int i,f;
printf("Enter String: ");
gets(str);
printf("\nEnter Character to Replace: ");
ch1=getche();
printf("\nEnter Character with Replace: ");
scanf("%c",&ch2);
for(i=0;str[i]!='\0';i++)
{
if(ch1==str[i])
{
str[i]=ch2;
f=0;
break;
}
else
f=1;
}
if(f==0)
{
printf("\n character is Replaced");
printf("\n New string %s",str);
}
else
printf("\n character is not available to replace");
}
39. Write a program to delete a character in given string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[20],ch,str2[20];
int i,j=0;
printf("Enter String: ");
gets(str1);
printf("\nEnter Character to Delete: ");
scanf("%c",&ch);
for(i=0;str1[i]!='\0';i++)
{
if(ch!=str1[i])
{
str2[j]=str1[i];
j++;
}
}
str2[j]='\0';
strcpy(str1,str2);
printf("\n New string %s",str1);
}
No comments:
Post a Comment