Hi All,
My requirement is like this.It a part of a software devlopment team as i am devloping a tool its a part of it.
Its bit long but my explanation is clear to get it.
1)we need to read a data file using a description file.
Usage: programname <description_file> <data_file>
2)Then need to dump the datafile on the screen according to the description file.
Detailed descritpin is given below:
Thanks,
DP
Description file format:
========================
begin
columname datatype("delimeter");
columname datatype("delimeter");
.
.
.
.
end;
EXAMPLE:
--------
begin
name string("|");
age string("|");
sex string("\n");
end;
Datafile Sample:
===============
Deepak|23|M
puja|21|f
|XY|
OUTPUT WILL BE:
================
Record_1:
name:"Deepak"
age:"23"
sex:"M"
Record_2:
name:"puja:
age:"21"
sex:"F"
Record_3:
name:""
age:"XY"
sex:""
I think the picture is clear now what i am doing.
now i am telling about the important functions and structures i am using.
A) The below structure is used to describe the Description file.
typedef struct dml_s
{
char **col_headers;
char **column_delim;
int *col_datatype;
int *col_len;
int col_cnt;
int record_length;
int file_type; //file type can be fixed,delimeted or max len with delimeters
}dml;
concentrate on 3 columns :
===========================
char **col_headers; it will store the column headers from the description file.
char **column_delim; it will store the column delimeters from the description file.
int col_cnt; it will store the column count from the description file.
B) dml* extract_dml_info(char* description_fname,dml *record);
this function will read the description file and store the necessary information in the variables.
C) void read_delimeted(char *data_filename,char **delmimeter,char **header,int col_cnt);
now this fuction will take the data file name along with the data retured by the above function.
and displays data on the screen as per the output format.
++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++PROBLEM++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
1)When we pass hard coded values to the fucntion
void read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);
it works fine for any number of columns and any size of data file
e.g
char *delmimeter[]={"name","age","sex");
char *delimeter[]={"|","|","\n"};
2)When we pass values returned from extract_dml_info(char* description_fname,dml *record);
to the fucntion read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);
it works upto 10 columns.
when the column name exceeds 10
it shows "segmentation fault"
ANALYSIS:
==========
A)
if error in
read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);
then it should not have worked for hard coded values.
B)if error in extract_dml_info(char* description_fname,dml *record);
then it should not print datas extrated beyond 10 columns but it prints data for any number of
columns.
but as a whole
program fails if the column number from descrition file exceeds 10 columns.