Thread: question

  1. #1
    Unregistered
    Guest

    question

    im trying to check if a string is null ( has nothing in it)

    this is what i did:

    char *str[]={0};

    do {
    STUFF
    } while (str != NULL);

  2. #2
    Unregistered
    Guest
    if (str == "")
    {
    printf("The string is null!");
    }

  3. #3
    Unregistered
    Guest
    I think this would b the most effective way of doing it.

    char *str;
    if (str == NULL){
    do_stuff();
    printf("the string is null");
    }

    //mah-gnu-s

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    to compare strings use strcmp()

    alternatively a null string will have a length of 0 so strlen() will return 0.

    The previous example checks the pointer for null and not the string for 0 length.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM