Thread: Definition?

  1. #1
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    Definition?

    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;
    "Nay! But you love the present life!"

  2. #2
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44
    Ok, (been typing all day...)sorry, more clearly now:

    char * pch; = ???
    "Nay! But you love the present life!"

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    What error are you getting?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Its a pointer to a char. My advice: don't deal with pointers until you get to them in your study of C++.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    error:

    full piece of code snippet:
    Code:
    char * pch;
    pch=strstr (str, 'good');
    related error: "arguement of type "int" is incompatible with parameter of type "const char" *

    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
    
        }
    "Nay! But you love the present life!"

  6. #6
    Ah,

    A simple error:
    Code:
    pch=strstr(str, 'good');
    Try changing the pair of single quotes ('') to double quotes ("").

    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
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  7. #7
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    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]
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM