By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

Delimited by a chr(255)

P: n/a
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.
Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"James Prato" <j.*****@hotmail.comwrites:
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[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\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[i]\
);}return 0;}
Sep 18 '06 #2

P: n/a

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

Sep 18 '06 #3

P: n/a
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)
Sep 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.