Program to trim a given character from a string.

Answer Posted / raju kalyadapu

//Write a program to trim a Character from a Given String
#include<stdio.h>
int main()
{
int i,j;
char str[30],ch;
printf("Enter Any String: ");
gets(str);
printf("
Enter Character to Trim:");
ch=getchar();
for(i=0;i<strlen(str);i++)   
{
while(str[i]==ch)   
{
j=i;
str[i]=str[i+1];
while(j++<strlen(str))
{

str[j]=str[j+1];
}

}


}
str[i]='';
printf("
");
puts(str);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the benefit of using #define to declare a constant?

608


How can I read/write structures from/to data files?

547


what will be maximum number of comparisons when number of elements are given?

1410


How can you increase the size of a statically allocated array?

612


What is the difference between procedural and declarative language?

649






I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1495


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

667


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

1735


What is string concatenation in c?

568


What are the basic data types associated with c?

816


How the c program is executed?

632


How many types of functions are there in c?

581


What is local and global variable in c?

616


What are the features of the c language?

646


What is substring in c?

636