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

  • Thread starter Thread starter carl123
  • Start date Start date
AI Thread Summary
The discussion revolves around a C++ programming problem where the goal is to search for a specific character in a string. The user initially seeks help on how to implement this functionality. Participants emphasize the importance of showing effort in problem-solving. A key suggestion is to use the `strchr()` function, which is designed for character searching in strings. The user successfully resolves the issue by implementing `searchResult = strchr(personName, searchChar);`, confirming that the solution works as intended.
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) {
      cout << "Character found." << endl;
   }
   else {
      cout << "Character not found." << endl;
   }

   return 0;
}

Please, how do I got about this? Thanks
 
Technology 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!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top