Can any one define this (and its utility) for me, as concretely as possible? It is include in my code and only returns an error.
char * pch;
:confused:
Printable View
Can any one define this (and its utility) for me, as concretely as possible? It is include in my code and only returns an error.
char * pch;
:confused:
Ok, (been typing all day...)sorry, more clearly now:
char * pch; = ???
What error are you getting?
Its a pointer to a char. My advice: don't deal with pointers until you get to them in your study of C++.
full piece of code snippet:related error: "arguement of type "int" is incompatible with parameter of type "const char" *Code:char * pch;
pch=strstr (str, 'good');
Code:#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <windows.h>
using namespace std;
int main()
{
char str[]="good";
char grabber[256];
cout<< "Hello, how are you today?\n"<< endl;
cin.getline(grabber,256);
char * pch;
pch=strstr (str, 'good'); //Searching for “good” in ^ Char str
if(pch !=NULL)
cout<< "I am glad to hear you are doing well today."<< endl;
else
cout<< "Is anything wrong at all? Would you like to discuss it? \n"<< endl;
Sleep(50000);
return 0; //END
}
Ah,
A simple error:Try changing the pair of single quotes ('') to double quotes ("").Code:pch=strstr(str, 'good');
The function strstr() takes a string [array of characters] for the second argument. By sending 'good', that can cause simple issues because the single quotes are to define a single character while the double quotes define an array of characters.
- Stack Overflow
Does strstr() return an integer? Sounds like it does. You do seem to be trying to cover alot of c++ material at once. Take Zach's suggestion.
[edit]
nevermind, seems Stack Overflow solved the problem. strstr() doesn't return an int. I didn't even catch that S.O., just looked at the error.
[/edit]