Thread: Help! Losing the top of my binary search tree...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you want to stop the loop when strtok is set to null, that has to be the last statement in the loop:
    strtok fileword
    --> loop the loop while not null
    | call asearch
    | do the if-check
    | strtok fileword
    +-- loop the loop

    Maybe that will help, if I understand the question.

  2. #17
    Registered User
    Join Date
    Nov 2007
    Posts
    26
    Quote Originally Posted by tabstop View Post
    If you want to stop the loop when strtok is set to null, that has to be the last statement in the loop:
    strtok fileword
    --> loop the loop while not null
    | call asearch
    | do the if-check
    | strtok fileword
    +-- loop the loop

    Maybe that will help, if I understand the question.
    What I'm trying to do is get strtok to work its magic on the fileline variable until there are no more words in fileline for it to work its magic on. The fileline variable contains the first line out of the file and goes through the loop with strtok. When done it gets the next line and does the same thing until EOF.
    The problem is I don't know how to set the whileloop to terminate when strtok gets done with all the words in the fileline variable.

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Bizmark View Post
    What I'm trying to do is get strtok to work its magic on the fileline variable until there are no more words in fileline for it to work its magic on. The fileline variable contains the first line out of the file and goes through the loop with strtok. When done it gets the next line and does the same thing until EOF.
    The problem is I don't know how to set the whileloop to terminate when strtok gets done with all the words in the fileline variable.
    Yes -- that's what you and I posted. strtok returns NULL when there is nothing left in the input string to parse.

  4. #19
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I see you still havn't read the FAQ about feof and loops: http://faq.cprogramming.com/cgi-bin/...&id=1043284351
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST (Binary search tree)
    By praethorian in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 09:11 AM
  2. searching and insertion in a binary search tree
    By galmca in forum C Programming
    Replies: 1
    Last Post: 03-26-2005, 05:15 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Binary Search Tree, Inserting node
    By cheryl_li in forum C Programming
    Replies: 1
    Last Post: 09-13-2003, 03:53 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM