C++/c++

Advertisement


Question
sir i want to calculate the number of the character in a string without strlen and without string function.

Answer
If am not wrong your question is how to find the position of a character in string?

answer:

  char a[80],ch;
  int i;

cout<<"Enter the input string";
cin .getline(a,80,'\n');// takes the input string till enter is hit.
cout<<"Enter the character for which the number needs to be found:";
cin>>ch;
for(i=0;a[i];i++)
{
if(a[i] == ch)
{
cout<<"the character is"<<ch<<"and"<<"the number is "<<i;
}
}

does this answer your question? If not please rivert back.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Saikrishna

Expertise

I can answer questions in C (Basic and a little of advanced). I can't answer questions related to multi threading

Experience

2.6 years

Education/Credentials
I am a B-tech graduate majored in computer science.

©2016 About.com. All rights reserved.