Basic and GENERAL strtok question

This is a discussion on Basic and GENERAL strtok question within the C Programming forums, part of the General Programming Boards category; In strtok, if using in ala Code: char token = ","; // code here // str = strtok(line, token); if ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    84

    Basic and GENERAL strtok question

    In strtok, if using in ala
    Code:
    char token = ",";
    
    // code here //
    
    str = strtok(line, token);
    if line doesn't contain any tokens but is a string, would it return a base address/position?
    Then if used again, would return a NULL?

    This seems to be the case in some code im looking at, this correct?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here, 'token' is just a single character, not a string. Anyway, from the man page:
    The strtok() and strtok_r() functions return a pointer to the beginning
    of each subsequent token in the string, after replacing the token itself
    with a NUL character. When no more tokens remain, a null pointer is
    returned.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    84
    ? So what your saying is...

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,172
    If line does not contain token, NULL is returned.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. general question
    By a.mlw.walker in forum C Programming
    Replies: 25
    Last Post: 04-04-2009, 09:32 AM
  2. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 11:13 AM
  3. Very basic question
    By something___ in forum C Programming
    Replies: 13
    Last Post: 12-08-2004, 01:53 PM
  4. Visual Basic Question
    By Xeavor in forum Tech Board
    Replies: 5
    Last Post: 12-02-2004, 08:59 AM
  5. General question about C++ Programming/Computer Science
    By learning C++ in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-05-2004, 09:18 PM

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