reading from long string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yezi

    #1

    reading from long string

    Hi, ALL:

    My question is I need read from a long string step by step, say first
    read length 10 byes of string, process them, then read next 10 bytes of
    that string.

    Like the file operation fread. there is a pointer forwarding whenever I
    read chunk from the file. Is any string read function provide such
    kind of mechanism to record current pointer position of string?

    Thanks for any comments .

    bin YE

  • winnie

    #2
    Re: reading from long string


    yezi wrote:[color=blue]
    > Hi, ALL:
    >
    > My question is I need read from a long string step by step, say first
    > read length 10 byes of string, process them, then read next 10 bytes of
    > that string.
    >
    > Like the file operation fread. there is a pointer forwarding whenever I
    > read chunk from the file. Is any string read function provide such
    > kind of mechanism to record current pointer position of string?
    >
    > Thanks for any comments .
    >
    > bin YE[/color]

    Why not operate the pointer by yourself?e.g. doing p+=10 every step
    will record the current position in p,i think.

    Comment

    • Keith Thompson

      #3
      Re: reading from long string

      "yezi" <ye_line@hotmai l.com> writes:[color=blue]
      > My question is I need read from a long string step by step, say first
      > read length 10 byes of string, process them, then read next 10 bytes of
      > that string.
      >
      > Like the file operation fread. there is a pointer forwarding whenever I
      > read chunk from the file. Is any string read function provide such
      > kind of mechanism to record current pointer position of string?[/color]

      No, there's no standard function to do this -- but you don't need one.
      All you need to do is keep track of where you are in the string,
      either with an integer index or with a pointer.

      For example, given:

      const char *s = "hello, world";

      s is a pointer to a string whose value is "hello, world", and s+7 is a
      pointer to a string whose value is "world".

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      Working...