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 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top