Click here to Skip to main content
15,662,823 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Given a string Str and a character C, your task is to remove the first and last occurrence of the character C from the string Str.

Input Format

• First line of input consists of a string value, denoting str

Second line of input consists of a character denoting C


• 1 <= str.length <=100

Output Format

• Print the string after the above operation

Sample Input


Sample Output


What I have tried:

yes i tried but it comes error what is the solution of this question
Updated 22-Feb-23 16:28pm
Richard Deeming 22-Feb-23 9:50am    
Nobody here is going to do your homework for you. If you don't know where to start, then talk to your teacher.
Dave Kreskowiak 22-Feb-23 22:29pm    
If you don't show the code you wrote for this, you're not going to get help on it.

Try with starting some Learn C tutorial or some video tutorial. Take care to understand strings as characters in the memory of the computer.

some tips: use functions and structs with understandable names and install some IDE like Visual Studio..
Share this answer
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are getting compiler errors when you try to build your code, then you should expect to get them every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
yes i tried but it comes error

Where is the code that could generate errors and what is the error message?

1 <= str.length <=100
If this notation is supposed to work, it is C++, because this statement does not exist in C.

Since there are input lines, it probably makes sense to open and read a file where these lines are.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900