Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Delimited by a chr(255)

Reply
Thread Tools

Delimited by a chr(255)

 
 
James Prato
Guest
Posts: n/a
 
      09-18-2006
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.


 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      09-18-2006
"James Prato" <(E-Mail Removed)> 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[]="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;}
 
Reply With Quote
 
 
 
 
kondal
Guest
Posts: n/a
 
      09-18-2006

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

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-18-2006
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
Comma Delimited Yama ASP .Net 1 12-16-2003 03:46 AM
import delimited text file to msde TJS ASP .Net 0 10-28-2003 08:40 PM
split a tab delimited string Ajit ASP .Net 6 07-29-2003 03:32 PM



Advertisments