Assign a pointer to any instance of searchChar in personName to searchResult.

  • Topic:
  • Thread starter Thread starter carl123
  • Start date Start date
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 13K views
carl123
Messages
55
Reaction score
0
HTML:
#include <iostream>
#include <cstring>
using namespace std;

int main() {
   char personName[100] = "Albert Johnson";
   char searchChar = 'J';
   char* searchResult = 0;

/* Your solution goes here */

   if (searchResult != 0) {
      count << "Character found." << endl;
   }
   else {
      count << "Character not found." << endl;
   }

   return 0;
}

Please, how do I got about this? Thanks
 
Physics news on Phys.org
MHB: General rules. 11. Show some effort.

It's hard to know what you need help with or what you're struggling with. For example, do you need help with understanding the wording of the problem? Do you need to know what variable to use or datatypes?

I would use strchr() for this problem.
 
smilesofmiles said:
I would use strchr() for this problem.

Ok, I was able to figure it out. I added this:
Code:
searchResult = strchr(personName, searchChar);
and it works. Thanks!