Thread: string tokenizer

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    31

    string tokenizer

    I am trying to find a file type through the file extension. I am trying to use string tokenizer to get the file type. How do i use strtok. what i have done is

    Code:
    char * temp = strtok(filename, ".");
    The things is how do i get the file extension by its self? Some files have '.' in the filename, but i am only interested in the last few characters after the last '.'

    Any hints?

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why bother tokenizing? Just use strrchr, and it'll give you the last occurance of the character in the string.


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

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by mbooka
    I am trying to find a file type through the file extension. I am trying to use string tokenizer to get the file type. How do i use strtok. what i have done is

    Code:
    char * temp = strtok(filename, ".");
    The things is how do i get the file extension by its self? Some files have '.' in the filename, but i am only interested in the last few characters after the last '.'

    Any hints?

    thanks
    dont use strtok it alters u's your original string. better use strchr as Quzah says

    ssharish2005

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Actually I suggested strrchr, to find the last occurance.


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

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    31
    thanks, works the charm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. String tokenizer and delimiters
    By John_L in forum C Programming
    Replies: 5
    Last Post: 11-06-2007, 07:22 PM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM