how to find the position of a particular character in a given string in c

Recommended Answers

All 4 Replies


Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download file.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.


how to find the position of a particular character in a given string in c

Show an attempt at trying to do this yourself. It is more useful then just asking for the answer.

commented: that's what I said ;o) +17

You can start by asking two inputs from the user
namely the word and letter

then use a for loop and if else statement to get the index position


					printf("The position of the letter is %d\n",i);

Of course there are missing pieces of this code you figure out the rest or maybe make a code of your own.

P.S. N1GHTS and WaltP are right you should post a code of your own and tell us the problem and not just ask us for an instant code

Here is the code,If you like this code plz dont forget to to click on upper arrow mark on right corner of my post..

      char str[50],ch;
      int i;
      printf("Enter String : ");
      printf("Enter Character of which you want to kmow position : ");
                               if (str[i]==ch)
                               printf("Character %c found at position %d",ch,i+1);
commented: Not only is the code awful, we frown on giving away answers. So I'll click on the *down* arrow instead of the requested up arrow. -4
commented: Any well written code should include comments, especially if you are trying to use the code to teach some lesson -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.