Jul 6, 2008

Dumping Fields Into Variables

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

Dumping Fields Into Variables

kvarnerexpress
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!

Reply

mizako
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



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : dumping fields variables

  1. C++ Lesson 2: Variables - Tutorial for C++ (0)
  2. The Difference In Variables? - (3)
    Hi y have a cuestion what is the diference or INT.VAR AND CHAR.VAR thanks /wink.gif' border='0'
    style='vertical-align:middle' alt='wink.gif' /> ...



Looking for dumping, fields, variables

Searching Video's for dumping, fields, variables
advertisement



Dumping Fields Into Variables



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE