'pch' undeclared

This is a discussion on 'pch' undeclared within the C++ Programming forums, part of the General Programming Boards category; Can anyone explain this error? I am trying a return of 2 substrings from one primary string; I thought this ...

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

    Question 'pch' undeclared

    Can anyone explain this error? I am trying a return of 2 substrings from one primary string; I thought this was the way to do it. ? ?

    Code:
    #include <stdio.h>
    #include <fstream>
    #include <iostream>
    #include <string.h>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    char resp1[]="good"; 
    char name[256];
    
    
    cout<< "Hello, how are you today?\n"<< endl;                     
    cin.getline (name,256);
    
    char a * pch;
    pch=strstr (name, "good"); //Searching for “good” in  ^ Char str
    
    
    
    if(pch !=NULL) //-INSERT // removed ! mark
    
    
    char b * pch;//-INSERT
    pch=strstr (name, "not");//-INSERT
    
    if(pch !=NULL) //-INSERT // removed ! mark
    
    
    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!"

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code:
    int main()
    {
        char resp1[]="good"; 
        char name[256];
    
        cout<< "Hello, how are you today?\n"<< endl;                     
        cin.getline (name,256);
    
        char a * pch;
        pch=strstr (name, "good"); //Searching for “good” in  ^ Char str
    You have not defined a variable called pch prior to its use in the above code fragment. Perhaps the a variable above is really meant to be pch?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Let's add some actual indentation and see what we get, shall we?
    Code:
    int main()
    {
        char resp1[]="good"; 
        char name[256];
    
        cout<< "Hello, how are you today?\n"<< endl;                     
        cin.getline (name,256);
    
        char a * pch;
        pch=strstr (name, "good"); //Searching for “good” in  ^ Char str
    
        if(pch !=NULL) //-INSERT // removed ! mark
            char b * pch;//-INSERT
    
        pch=strstr (name, "not");//-INSERT
    
        if(pch !=NULL) //-INSERT // removed ! mark
            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
    }
    See those two lines? Remember the proper way to declar a variable?
    Code:
    type name = optionalinitialization;
    Now look at what you're doing:
    Code:
    char b * pch; //-INSERT
    All of that orange colored stuff is wrong.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The error is caused by not keeping to one thread for the same damn program!

  5. #5
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,810
    <trying to be cool by agreeing with thantos>
    YAH!
    </trying to be cool by agreeing with thantos>
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 10:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21