kvarnerexpress 0 Report post Posted February 22, 2005 have a file that we are supposed to use as input. It looks like this:Code:name:curriculum:gradyear:ssn:dobI'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! Share this post Link to post Share on other sites
mizako 0 Report post Posted February 23, 2005 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! 53011[/snapback] 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,':')); Share this post Link to post Share on other sites