Hi.
I am a begginer :cheesy: on the programming area and I am currently taking a course on C++. I have doubts :o about how to use the strchr function. Can somebody give me some hints? :?:

Thanks.

Hi.
I am a begginer :cheesy: on the programming area and I am currently taking a course on C++. I have doubts :o about how to use the strchr function. Can somebody give me some hints? :?:
Thanks.

This is part of the code, but how do I do to return the amount of vowels that the word has?

#include <stdio.h>
#include <string.h>
#include <iostream.h>
int main()
{
char word[30],
vowel1= 'a',


cout<< "\n\npalabra="<<word<<'\n' ;
cout<< "letra="<<vowel1<<'\n';
cout<< "strchr="<<strchr( word, vowel1) <<endl<<endl;

This is one simple example ...

// find and point to a given character in a string

#include <iostream>

using namespace std;

int main()
{
  char str1[] = "This is just a simple sample string!";
  char *pch;
  
  cout << "Looking for character s in \"" << str1 << "\"" << endl;
  
  // find the first occurance
  pch = strchr( str1, 's' );
  // then search further
  while( pch != NULL )
  {
    cout << "Found character s at index " << (pch - str1) << endl;
    pch = strchr( pch + 1, 's' );
  }
  
  cin.get();  // wait
  return 0;
}

In your case, add an extra loop and go through the vowels to sum them up.

Be a part of the DaniWeb community

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