why does my compiler (borland 5) not recognize strtok()?

This is a discussion on why does my compiler (borland 5) not recognize strtok()? within the C++ Programming forums, part of the General Programming Boards category; i have #include <string.h> but it doesn't recognize strtok()...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    25

    why does my compiler (borland 5) not recognize strtok()?

    i have
    #include <string.h>
    but it doesn't recognize strtok()
    I Love Jesus

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    post your code
    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

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Perhaps it is not implemented? Take a look into the file string.h, I guess there should be a prototype of the function.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    25
    #include <cassert.h>
    #include <conio.h>
    #include <cstdlib.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>
    #pragma argsused

    using namespace std;

    int main()
    {

    const int MAX_RECORD = 75;
    int position;
    char inChar;
    char quit;
    string seq_line;

    struct myRecord
    {
    char title[35];
    char system[4];
    double score;
    };

    fstream seq_in("sequential_file.txt", ios::in);
    fstream rel_file("relative_file.txt", ios::in | ios:ut);


    for (position = 1; position <=MAX_RECORD; ++position)
    {
    getline(seq_in, seq_line);
    strtok(position, '|');
    cout << seq_line << "\n";
    }

    cin >> quit;



    }
    I Love Jesus

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    as I thought you are not using strtok() correctly.

    The first time you call strtok to tokenise a string you pass the address of the string to be tokenised. Subsequent calls to strtok pass NULL and this tells strtok to keep tokenising the same string.
    here is an example...
    Code:
    /* strtok()'s a string and returns a singly linked list of the tokens */
    Node* Tokenise(char CopyString[],char* Delim)
    {
    	size_t Len;
    	char* TokenPtr;
    	Node* Head=NULL;
    	TokenPtr=strtok(CopyString,Delim);
    	Len=strlen(TokenPtr)+SPACE; 
    	Head=AddNode(Head,TokenPtr,Len);
    	while ((TokenPtr=strtok(NULL,Delim))!= NULL)
    	{
    		Len=strlen(TokenPtr)+SPACE;
    		Head=AddNode(Head,TokenPtr,Len);
    	}
    	return Head;
    }
    also your headers are wrong....
    you should be using
    <cassert> not <cassert.h>
    <cconio> not <conio.h> be aware that this is not a standard header
    <cstdlib> not <cstdlib.h>
    <iostream> not <iostream.h>
    <fstream> not <fstream.h>
    <cstring> not <string.h>
    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

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    25
    i know those header files are wrong. i usually use the non-.h ones, but for some reason i didn't here. thanks.
    I Love Jesus

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strtok with "" as delimiter?
    By fanoliv in forum C Programming
    Replies: 15
    Last Post: 06-19-2006, 12:44 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM

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