NULL problem??

This is a discussion on NULL problem?? within the C++ Programming forums, part of the General Programming Boards category; The below code is from my program. The variable 'input' is a line from a text file. I'm trying to ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    44

    NULL problem??

    The below code is from my program. The variable 'input' is a line from a text file.

    I'm trying to check if the line exists or not I am currently using NULL but it doesn't seem to work??

    Am I correct using the NULL command or is there a specific command for checking whether that line exists within a text file??

    Code:
    if (input == NULL)
    Thanks
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  2. #2
    Unregistered
    Guest
    You would be better served using int strcmp( string1, string2 ).
    It returns 0 if the two strings are the same.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    NULL is exactly the same as 0. It's not a command.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Write a function that takes a string as an argument and returns 1 if the string exists, 0 if it does not.

    Inside the function, run a loop that tests each character with the isgraph() function. isgraph is found in ctype.h

    Hope that helps!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    44
    Thanks that has helped but how do I check if a string exists or not?
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Are you trying to check for a blank line? If so, maybe:

    Code:
    bool is_blank_line(char *input)
    {
       int i;
       if (strlen(input) == 0)
          return 1;
       else
       {
          for (i=0; i<strlen(input); i++)
          {
             if (!isspace(input[i]))
                return 0;
          }
       }
       return 1;
    }
    
    //In your main() function:
    #include <ctype.h>
    .
    .
       if (is_blank_line(input))
          cout << "line is blank.\n";
       else
          cout << "line is NOT blank.\n";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 08:53 PM
  2. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 01:00 PM
  3. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 04:43 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 11:45 PM

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