QUOTE(kvarnerexpress @ Feb 22 2005, 11:01 PM)
have a file that we are supposed to use as input. It looks like this:
Code:
name:curriculum:gradyear:ssn:dob
I'm going to read it in a buffer, but trying to find the logic to seperate the fields and then place in a variable. I was thinking something like:
Code:
if(ispunct(buf[x]) != ':')
strcpy(s->name, buf);
Any suggestions is greatly appreciated!
You can use the strtok() function.
As a pseudocode example:
char *aux;
/* Buffer contains name:curriculum:gradyear:ssn:dob*/
aux = buf;
/* i suppose s is a structure with the fields name, curriculum ..... and the memory for this fields has been already alloced, if not use strdup instead of strcpy */
strcpy (s->name,strtok(aux,':'));
strcpy (s->curriculum,strtok(NULL,':'));
strcpy (s->gradyear,strtok(NULL,':'));
strcpy (s->ssn,strtok(NULL,':'));
strcpy (s->dob,strtok(NULL,':'));
Reply