Breaking string into tokens

This is a discussion on Breaking string into tokens within the C Programming forums, part of the General Programming Boards category; hiee everyone.. i wanted to know about how to break a string into tokens.I have a file and i need ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    21

    Breaking string into tokens

    hiee everyone..
    i wanted to know about how to break a string into tokens.I have a file and i need to read 16 characters at a time at the display.so i need to break the file after every 16 bits.i know the string tokenizer function in java but em not very sure about C.plz help me with this.
    Thanx,
    cutelucks

  2. #2
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    Look up strtok(), but I'm not sure that's what you really want. Can you describe your problem a different way?

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    16 chars and 16 bits are different things

    to read fixed number of bytes - use fread
    to read upto fixed number of bytes or the new line symbol - use fgets
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    21
    actually i have a text file.i need to read and dislay the file on an LCD which takes 16 characters at a time.so i need to break the file after every 16 characters and then call the display function.i am not sure about how to do this in C

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Here is the pseudocode
    Code:
    char buf[17];
    int len;
    while((len = fread(buf,16,f)) > 0)
       display(buf,len);
    The buffer is 1 byte longer if you want to put zero char before priniting at the end
    If you need special processing for several chars like EndOfLine - read 16 chars in loop and then print them
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 01:54 PM

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