reading from long string

Y

yezi

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
 
W

winnie

yezi said:
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

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

Keith Thompson

yezi said:
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?

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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top