#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#define MAXFIELDS 100
#define MAX_LENGTH 245
char *dex_data[MAXFIELDS];
#define ON 1
#define OFF 0
#define ALL_OK 0
#define NOT_OK 1
#define YES 1
#define NO 0
/*********************************************************************/
/* Parse: This function parses each field between the '*'s and */
/* returns the number of fields parsed. */
/*********************************************************************/
int Parse(char *source_strng, char *dex_field[]) {
char *ptr;
short field_count = 0;
short str_ix = 0;
short done_sw = NO;
short new_fld_sw = YES;
/* clear out array of dex_field pointers */
field_count = 0;
while ( field_count < MAX_FIELDS ) {
dex_field[field_count] = NULL;
field_count++;
}
field_count = 0;
while ( done_sw == NO ) {
/* if we hit a newline, the file contains garbage or only the TRLR record */
if ( source_strng[str_ix] == '\n' ) {
field_count = 0;
done_sw = YES;
}
else {
/* DEX data strings end with Carriage Return and Line Feed characters */
if ( (source_strng[str_ix] == CR) && (source_strng[str_ix+1] == LF) ) {
source_strng[str_ix] = NULL; /* end data field with NULL */
dex_field[field_count] = ptr;
done_sw = YES;
}
else {
if ( source_strng[str_ix] == '*' ) {
source_strng[str_ix] = NULL; /* end data field with NULL */
dex_field[field_count] = ptr;
field_count++;
ptr = NULL;
new_fld_sw = YES;
}
else {
if ( new_fld_sw == YES ) {
ptr = &source_strng[str_ix];
new_fld_sw = NO;
}
}
str_ix++;
}
}
} /* end of while ( done_sw == NO ) */
return(field_count);
}
FILE *Dex_infile;
int main(void) {
// your code goes here
short rd_rc;
dex_data
= malloc(sizeof(char *)*MAXFIELDS
);
int p;
for(p=0; p < MAXFIELDS ; p++)
dex_data
[p
] = malloc(sizeof(char)*MAX_LENGTH
);
if( ( Dex_infile
= fopen(ws_fullpath_name
,"r") ) == NULL
) { printf("Can Not Open DEX Input File"); }
fgets(in_buf
,sizeof(in_buf
),Dex_infile
);
if(Parse(in_buf,dex_data) > 0){
rd_rc = 0;
}
return 0;
}