Checking if true...

This is a discussion on Checking if true... within the C Programming forums, part of the General Programming Boards category; I have a function: Code: bool tester(const char *mytest) that returns true or false. In another function, I'm calling: Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    83

    Checking if true...

    I have a function:
    Code:
    bool tester(const char *mytest)
    that returns true or false.

    In another function,
    I'm calling:
    Code:
    if (tester(const char *mytest) == true)
        printf("Good to go.");
    But the compiler is saying this doesn't work.
    Why? How can I fix it?
    Thank you.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Example:
    Code:
    #include <stdbool.h>

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    83
    Thanks, but that didn't do it.
    error: 'mytest' undeclared (first use in this function)

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to call it with the actual string you want to call it on, not the parameter name in the function prototype.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    if (tester(mytest) == true)
    perhaps? Obviously assuming that "mytest" is a pointer to a char of some sort.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Full code, por favor.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    83
    But I just want to know if it returned true... the string it is calling is in another function so it will say its an unitialized reference

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well -- but if you don't have the string, then you can't call the function. Tell us what you're actually trying to do (preferably with code) and we'll go from there.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by pollypocket4eva View Post
    But I just want to know if it returned true... the string it is calling is in another function so it will say its an unitialized reference
    You can't pass a string that you haven't got to a function. You would need to pass back the string to the function where you need it (or perhaps pass back the bool result of the check?).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by master5001 View Post
    Full code, por favor.
    Good suggestion.

    Quote Originally Posted by tabstop View Post
    ... (preferably with code) ...
    Genious!

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    >> Full code, por favor.

    I am seriously considering making that my new signature. *sigh*
    Last edited by Sebastiani; 11-17-2008 at 06:08 PM. Reason: grammer
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I would, but my haiku strikes my preference for now.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    You do realize that it prints "I like haiku muchbye", right?
    Last edited by Sebastiani; 11-17-2008 at 06:10 PM. Reason: um, grammer.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I was more concerned about the number of syllables each line of code used. But I can fix it

  15. #15
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by pollypocket4eva View Post
    But I just want to know if it returned true... the string it is calling is in another function so it will say its an unitialized reference
    You can't call a function in one place, then check it's return value in another place.
    Check the return value when you call it properly, then you can do whatever you want with that return value.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  2. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 06:12 PM
  3. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  4. I don't understand this, help? ((boolean))
    By Raeliean in forum C++ Programming
    Replies: 5
    Last Post: 07-03-2005, 06:08 PM
  5. tile map bounds checking
    By Natase in forum Game Programming
    Replies: 1
    Last Post: 10-08-2003, 11:00 AM

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