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
    Posts
    5,439
    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:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 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, 07:53 PM
  2. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 12:00 PM
  3. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 03:43 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

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