141k views
3 votes
Assign the variable 'searchresult' with a pointer to any instance of the character 'searchchar' in the string 'personname'. Use the function 'strchr()'.

1 Answer

3 votes

Final answer:

To assign the variable 'searchresult' with a pointer to any instance of the character 'searchchar' in the string 'personname', use the function 'strchr()' in C programming language.

Step-by-step explanation:

To assign the variable 'searchresult' with a pointer to any instance of the character 'searchchar' in the string 'personname', you can use the function 'strchr()' in C programming language. Here's how you can do it:

  1. Declare a pointer variable 'searchresult' of type char*.
  2. Assign the result of 'strchr(personname, searchchar)' to 'searchresult'.
  3. If 'searchresult' is not NULL, it means 'searchchar' was found in 'personname'.

For example:

char* searchresult;
char* personname = "John Doe";
char searchchar = 'D';

searchresult = strchr(personname, searchchar);

if (searchresult != NULL) {
printf("%c was found in personname.\\", searchchar);
}

User Mosesfetters
by
8.2k points