home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_12
/
1012077a
< prev
next >
Wrap
Text File
|
1992-10-13
|
689b
|
36 lines
/* token3.c: Read comma-delimited fields */
#include <stdio.h>
#include <string.h>
main()
{
char s[81];
while (gets(s))
{
char *p, *sp = s;
int nchars;
do
{
/* Make p point at next comma, or '\0'*/
if ((p = strchr(sp,',')) == NULL)
p = sp + strlen(sp);
nchars = p - sp;
/* Print the field */
if (sp > s)
putchar(',');
printf("\"%.*s\"",nchars,sp);
/* Position at start of next field */
sp = p+1;
} while (*p != '\0');
putchar('\n');
}
return 0;
}