Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,122 people online right now. Registration is fast and FREE... Join Now!




reading and sorting

 
Reply to this topicStart new topic

reading and sorting

beginnerInC
1 Oct, 2006 - 05:43 PM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2006
Posts: 8


My Contributions
i have the following file: bhp.csv which has the following format:
QUOTE

BHP,"27 Aug 2002",9.53,9.56,9.45,9.45,8117955
BHP,"26 Aug 2002",9.45,9.48,9.4,9.48,6990617
BHP,"28 Aug 2002",9.54,9.55,9.4,9.44,12771227
BHP,"29 Aug 2002",9.31,9.31,9.21,9.27,11986227
BHP,"30 Aug 2002",9.21,9.23,9.11,9.11,19340245
....
....
....

where comma is delimeter.
i have to read the file, than split the columns into a data structure. than i have to sort the date column and the second last column. than i have to search in this columns for a query entered by the user.
i have a problem reading my bhp.csv file.
my code is the following.
CODE



#include <stdio.h>
#include <string.h>

#define ROW 762
#define COL 7
#define MAX_LENGTH 60

typedef struct{
    int day;
    char month[3];
    int year;
    }DATE;
    
typedef struct{
    char filename[20];
    DATE date;
    float third;
    float forth;
    float fifth;
    float ClosePrice;
    float seventh;
    }BHP;

/* functions prototypes*/
int BinarySearch( char buffer[ ], float X, float N );

int main(void)
{
    FILE* infile;
     char buffer[ROW];
    
    int i,j,k;
/*      struct BHP result[100];*/
    char delims[] = ",";
    char *result = NULL;
    
    
    infile = fopen("bhp.csv","r");
    if (infile == NULL)
    {
        printf("Error opening file!!!\n");
        return 0;
    }
for(i=0;i<ROW;++i)
    {
    fgets(buffer,MAX_LENGTH,infile);
    /*puts(buffer);*/
    }

/* spliting the columns*/

for(i=0;i<ROW;++i)
    for(j=0;j<COL;++j)
{
    result = strtok(buffer, delims );
    
    /*fscanf(infile,"%f",&result);
      while(!feof(infile))*/
        {
            printf("result is \"%s\"\n",result);
        }
}

free(buffer);
fclose(infile);
    







    return 0;
}

/*
int BinarySearch( char buffer[ ], float X, float N )
        {
            float Low, Mid, High;

     Low = 0; High = N - 1;
      while( Low <= High )
            {
          Mid = ( Low + High ) / 2;
          if( buffer[ Mid ] < X )
              Low = Mid + 1;
                else
          if( buffer[ Mid ] > X )
              High = Mid - 1;
                else
              return Mid;
            }
      return -1;    
        }
*/

/* sorting close price*/

/*void bubbleSort(int numbers[], int array_size)
{
  int i, j, temp;

  for (i = (array_size - 1); i >= 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (numbers[j-1] > numbers[j])
      {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}
*/

/* sorting in relation to date*/
/*

*/



can anyone help be reading the fiel and than doing the operations i have to do?
please check my code.

This post has been edited by Dark_Nexus: 1 Oct, 2006 - 11:03 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:01AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month