Delimited by a chr(255)

Discussion in 'C Programming' started by James Prato, Sep 18, 2006.

  1. James Prato

    James Prato Guest

    In C, how do you read data fields from a file that are separated/delimited
    by a chr(255)?

    For example, Field1chr(255)Field2chr(255), etc where Fieldx could be NULL.
     
    James Prato, Sep 18, 2006
    #1
    1. Advertising

  2. James Prato

    Ben Pfaff Guest

    "James Prato" <> writes:

    > In C, how do you read data fields from a file that are separated/delimited
    > by a chr(255)?


    You could read characters with fgetc() until you encounter a
    character with value 255. (In C, we don't use your "chr"
    notation; perhaps you are more familiar with Pascal or Perl than
    with C.)

    Have you tried writing code to do this? What difficulties did
    you encounter? It is quite straightforward.
    --
    int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
    \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
    );while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p\
    );}return 0;}
     
    Ben Pfaff, Sep 18, 2006
    #2
    1. Advertising

  3. James Prato

    kondal Guest

    James Prato wrote:
    > In C, how do you read data fields from a file that are separated/delimited
    > by a chr(255)?
    >
    > For example, Field1chr(255)Field2chr(255), etc where Fieldx could be NULL.


    The question is unclear to me. Did you meant Field1 and Field2 are
    character buffers of size of 255 or you meant the strings are seperated
    by ascii character 255?

    -kondal
     
    kondal, Sep 18, 2006
    #3
  4. kondal said:

    >
    > James Prato wrote:
    >> In C, how do you read data fields from a file that are
    >> separated/delimited by a chr(255)?
    >>
    >> For example, Field1chr(255)Field2chr(255), etc where Fieldx could be
    >> NULL.

    >
    > The question is unclear to me. Did you meant Field1 and Field2 are
    > character buffers of size of 255 or you meant the strings are seperated
    > by ascii character 255?


    Neither. He didn't mention ASCII, and he didn't mention buffer sizes.

    He is trying to tokenise on a given character, that's all. The solution is a
    simple getc loop.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Sep 18, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. crjunk
    Replies:
    2
    Views:
    16,874
    crjunk
    Aug 8, 2003
  2. Girish
    Replies:
    0
    Views:
    488
    Girish
    Jan 23, 2004
  3. Jakir
    Replies:
    2
    Views:
    1,385
    Jakir
    Aug 26, 2004
  4. James
    Replies:
    53
    Views:
    1,253
    Roedy Green
    Sep 29, 2005
  5. RyanL
    Replies:
    6
    Views:
    701
    Paul McGuire
    Aug 28, 2007
Loading...

Share This Page