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

  • Thread starter Thread starter carl123
  • Start date Start date
Click For 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!
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
4
Views
2K
Replies
3
Views
1K
Replies
5
Views
2K
Replies
12
Views
3K
  • · Replies 89 ·
3
Replies
89
Views
6K
  • · Replies 15 ·
Replies
15
Views
4K
Replies
73
Views
6K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 66 ·
3
Replies
66
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K