Thread: Breaking string into tokens

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    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

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    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. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04: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-27-2003, 12:03 AM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 02:54 PM