date

This is a discussion on date within the C++ Programming forums, part of the General Programming Boards category; Hi John_ I do not have any problem with these previous links, I fixed all the problem with these in ...

  1. #16
    hi5
    hi5 is offline
    Registered User
    Join Date
    Feb 2006
    Posts
    12
    Hi John_
    I do not have any problem with these previous links, I fixed all the problem with these in the past. They are working perfectly and gives the right result and I check the out put even manually, and I submitted that part.

    the new requirement for the same file is to get the date from the fistr column just once because,if you check the L_05.csv you will find that all the date column are the same for aspecific date.

    When you said you only getting 0 it is making me because In my runnin or debugging I am getting 10 the dd of the date column.

    the L_05.csv I post is part from I big on, because it did not let me post the whole csv or even zip as it has a big file size. may be thats why you may be getting 0 result. I would like to post you the whole L_05.csv but I am not sure how.

    thank you
    Last edited by hi5; 02-02-2006 at 06:37 AM.

  2. #17
    hi5
    hi5 is offline
    Registered User
    Join Date
    Feb 2006
    Posts
    12

    any idea

    if I am getting only the dd from the dd/mm/yyyy so I think my format is not right for the function.

    any ideas I am absolutly stack with this function

    I do not think SIZE is the problem becuase even if you change the code to SIZE=9 is giving wrong result only 0s.


    If I know how to solve it I would but I am not, that why I came to you guys, any suggestion with it.
    Last edited by hi5; 02-02-2006 at 06:43 AM.

  3. #18
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    Sorry if my questions seem pointless, the reason I am asking them is to try and understand the code better and see if something could be causing a problem. The reason I thought the SIZE was the problem, was because I thought you wanted it to output the other columns.

    Now I know that you only want to output 1 column it makes sense.

    Is there 1447 lines in this file?

  4. #19
    ZuK
    ZuK is online now
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    For a start you could try to make clear what you really want. You say you want to find out a date from the first column of a csv-file. At the same time you declare your function that is supposed to return the date with a return-type of float. So how do you want to encode a date in a float ?. Your code looks like you are reading a lot of lines from the file but at the same time you say all lines contain the same date. You say you want to post a sample csv-file but you post an xls-file. ( i cannot read that. this is not a windows-box ). If the forum doesn't let you post the csv you could just rename it. If its too big, post a part of it.
    You are making it hard to help you.
    Kurt

  5. #20
    hi5
    hi5 is offline
    Registered User
    Join Date
    Feb 2006
    Posts
    12
    Hi John_
    yes 1447 row and 196 column, in my original csv file I left the first 6 row as they not rquire. from 7 row where you will find the heading of each column, starting from row 8 you will find the 10/10/2004.

    in that file the date of the first column will repeated in all the 1447 rows, so getting one value of the date would be more than enough.

    I really sorry for keep asking, as I feel Iam lost and thank you for all you effort to solve my problem, I am gratefull.

    can anyone suggest a new function or a way to get that date only once.
    Attached Files Attached Files
    Last edited by hi5; 02-02-2006 at 08:12 AM.

  6. #21
    ZuK
    ZuK is online now
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    This way you can get the value of any column in the file as string.
    If you need the date in some other format you have to convert it.
    Code:
    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    // string GetdateValue(int column,string line) {
    string GetColumnValue(int column,string line) {  // use meaningful names
         string temp;
         stringstream sstr(line);
         for( int i = 0; i < column; ++i )
            getline(sstr,temp,',');  // read into temp separated by ','
         return temp;                // return last read value
    }
     
    int main() {
        ifstream input_file("Log_05.txt");// is a scv file have many coulmn first column of it is the date
        string line;
        int count;
        string date_str;   // they are all the same
        string time_str;   // for demonstration
         
        if ( input_file.fail ()) { 
             cout << "Error opening file.";
         }
         else  {
             count = 0;
             while( getline(input_file,line) && count <= 1447) {  // while there is no error and linecount < 1448 if you want it like this
                if ( count == 20 ) {         // get date from line 20 
                   date_str = GetColumnValue( 1, line ); // date is col 1
                   time_str = GetColumnValue( 2, line ); // time is col 2
                }
                count++;        // Increment the count, to go to the next line
             }
             cout << "date is '"<< date_str << "' time is '" << time_str << "'" << endl;        
        }
        return 0;
    }

  7. #22
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    I really don't believe this.

    I thought the .xls file he uploaded was the csv file but just renamed because the forum didn't accept that attachment type. It is the reason I asked him to post the file so I could see the format of it.

    It wasn't even the correct file I had, I just renamed it to .csv, no wonder I wasn't getting anywhere.

  8. #23
    hi5
    hi5 is offline
    Registered User
    Join Date
    Feb 2006
    Posts
    12
    thank you all for all the effort, I would not be able to do it without your help.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  4. CDate Class - handle date manipulation simply
    By LuckY in forum C++ Programming
    Replies: 5
    Last Post: 07-16-2003, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21