0

Hi

see this code

```
#define MAX_LINE_LENGTH 1024
#define MAX_TOKEN_LENGTH 32
typedef struct max_min
{
char maximum[MAX_TOKEN_LENGTH];
char minimum[MAX_TOKEN_LENGTH];
} m_and_m;
```

`enum data_type{enumber};`

in your main program did this

```
m_and_m max_number;
FILE *fp;
int result;
/*Open input file*/
fp = fopen("read.csv","r");
if (fp != NULL)
{
max_number = get_max_min(fp,11,5,enumber);
rewind(fp);
result = 0;
}
```

this the file function

```
m_and_m *get_max_min(FILE *fp,unsigned start_from_line,unsigned start_from_column,enum data_type dtype)
{
m_and_m *result;
unsigned i;
char current_max[MAX_TOKEN_LENGTH],current_min[MAX_TOKEN_LENGTH],*token;
char current_line[MAX_LINE_LENGTH];
/*Use fgets to get one line prior to the desired start line*/
for (i = 0;i < start_from_line - 1;i++)
{
fgets(current_line,MAX_LINE_LENGTH,fp);
}
/*While there are lines to read*/
while (fgets(current_line,MAX_LINE_LENGTH,fp))
{
/*Read tokens using strtok until you get to the desired start column*/
i = 0;
token = strtok(current_line,",");
while (token != NULL && i < start_from_column - 1)
{
token = strtok(NULL,",");
i++;
}
/*Do the actual comparisons to find current_max and current_min*/
switch (dtype)
{
case (enumber) :
printf ("Comparing numbers.\n");
strcpy(current_max,compare_number(current_max,token));
strcpy(current_min,compare_number(current_min,token));
break;
default :
fprintf (stderr,"Undefined data type.\n");
break;
}
}
/*Store the result in an m_and_m type variable and return it*/
result = (m_and_m *)malloc(sizeof(m_and_m));
if (result != NULL)
{
strcpy(result->maximum,current_max);
// strcpy(result->minimum,current_min);
}
else
{
fprintf(stderr,"Failed to allocate memory.\n");
}
return (result);
}
```

now if you want to buit you max and min function.

```
char *compare_number(char *first_number,char *second_number)
{
char *result;
return (result);
}
```

how you can build the above function copmare number