reading a string into a structure
what iv'e done so far is read data from a dat file into a string, then validated it by checking there was enough data to fill the feilds in the struct then passed the string to a function.
here's where i fall over(doh!)
I need to read a string into a structure, so that i can run further validation test on 2 of the 4 members
switch(opt)
{
case 'I' :
case 'R' : f_num = sscanf(buff, "%1c %5s %6s %4d", &I_R_RECORD.rec_type,&I_R_RECORD.cust_code,
&I_R_RECORD.part_num, &I_R_RECORD.quantity);
if(f_num != 4)
error_rep(buff, error(5));
else
rpt(buff);
/*here iv'e check for the correct amount of records*/
/*and then passed the str to rpt();*/
void rpt(char *buff)
{
char code[6], part[7];
char *chk_digit, *chk_d;
FILE *fp;
while(fscanf(fp, "%[^\n]\n", buff) !=NULL)
{
while(fscanf(fp,"%1c%6s%7s%4d", &I_R_RECORD.rec_type,
&I_R_RECORD.cust_code,
&I_R_RECORD.part_num,
&I_R_RECORD.quantity) != '\n')
{
/*i know this doesn't work so any pionters on how to solve it*/
/*will be received with warm hands*/
chk_d_cust_num(code);
if(chk_digit)
strncat(I_R_RECORD.cust_code, chk_digit, 6);
else
error_rep(buff, error(1));
chk_d_part(part);
if(chk_d)
strncat(I_R_RECORD.part_num, chk_d, 7);
else
error_rep(buff, error(2));
}
}
fputs(buff, valid_rec_fp);
return;
}
Thanx in advs