Thread: Looking for help with reading data from csv file or memory onto screen ..

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    4

    Red face Looking for help with reading data from csv file or memory onto screen ..

    Hi .. I am a bit of a newbie C programmer but I know some.

    But I do need help on this one.

    I have a csv file (comma delimited text file really) and I have data ,about 6400 lines, and I need to read and display data from 1 line.
    At the bottom is sample data from my csv file.

    I want to read onto the screen the 3rd item .. ie Test User 1 and the date and time at the end (the last 2 items).

    I will enter in a number .. from which I will want to retrieve the appropriate record .. in this case I would enter in 514, 563 or 874 and get back the info for that record.

    This is a DOS 16 bit application .. and I know that some of the data is in memory already but I am not sure how to tell .. or how to retrieve it.

    I do have the ability to save the data to the file at any time .. so I can use that to ensure that the data is current in the text file
    before I retrieve the data from this 1 row.

    I think that it may just be easier to get from the text file ? but I am not sure.

    0000,7,0,"Test User 1",53c145cb,db,5,514,514,2014/07/12,10:27:23
    0001,7,0,"Test User 2",53d7f,1903,10,563,563,2014/07/24,11:04:31
    0002,7,0,"Test User 3",529c,5ffb03,0,874,874,2013/12/02,09:07:58


    I am a database guy .. and I am just a bit lost when it comes to C programming as such.

    Any advice would be appreciated.
    Last edited by edmscan; 07-26-2014 at 09:49 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A development process
    Start simple, say by just writing the program which prints each line in turn.

    Then say copies the line to another file.

    Then say examines lines looking for interesting data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    4
    I actually have 75% of if it done ... I can enter in the particular number that I want .. ie 514 and get the info on the screen .. so "514 Test User 1" .. but I now need to add the date and time .. so "514 Test User 1 2014/07/12 10:27:23" as my finished result.

    So I am getting there. Just have to determine if that date / time data is in memory already .. and how to get it.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    I am a database guy .. and I am just a bit lost when it comes to C programming as such.
    Why did you choose C as the language in which to do this? Higher-level languages such as Python and Perl are far better suited for such a task.

  5. #5
    Registered User
    Join Date
    Jul 2014
    Posts
    4
    I didn't choose it ... trust me. The majority of the application was written a long time ago .. like 14 years ago. I just have been modifying it.
    I really need someone who knows C to look at my source code and suggest how to do what I want.

    If it was in like a database product .. and not C, it would take me all of about 3 min and 2.5 of that would be waiting for my pc to boot.

    I am beyond frustrated at this point.

    The data is possibly in an array (idList) but I don't really know how to tell what is actually stored in the array.

    I am willing to post the attach the original source code if someone could help me cause this is way beyond my knowledge of C.
    Last edited by edmscan; 07-26-2014 at 04:21 PM.

  6. #6
    Registered User migf1's Avatar
    Join Date
    May 2013
    Location
    Athens, Greece
    Posts
    385
    Have you considered googling for a csv parsing library and use one?

    About 2 months ago I wrote a rather limited and simple csv parser in C99 for a mini coding-challenge at a Greek forum.

    From the sample csv data you presented it seems it could help you (unless your csv files use multi-byte encodings)...
    .h
    .c

    PS. Feel free to customize/improve the code (for example, those huge macros should really be functions... I needed them guaranteed inlined, only for that coding challenge). Also, please note that it's not extensively tested, so it may contain bugs.
    Last edited by migf1; 07-26-2014 at 05:11 PM.

  7. #7
    Registered User
    Join Date
    Jul 2014
    Posts
    4
    I actually had someone help me .. from another forum. Not a C programming forum but a forum that is more to do with the program itself and he is a C programmer so he wrote me a csv parsing routine. I will work on that for the next while.
    But I am having more issues with getting my Watcom IDE to work .. it gives me an error of "No Targets Installed" when I try to create a project. I don't know if I can use any compiler .. as the original programmers used Watcom.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by edmscan View Post
    But I am having more issues with getting my Watcom IDE to work .. it gives me an error of "No Targets Installed" when I try to create a project. I don't know if I can use any compiler .. as the original programmers used Watcom.
    You likely need to use the Watcom compiler or hire someone to fix the code for another compiler.
    You also likely need to use the same version (or a close version) of the Watcom compiler.

    1. Have you compiled a hello world type project with your compiler to verify the compiler and IDE are working correctly.
    2. Next, try to compile the file you are planning to change without any changes to see if it compiles.
    3. You really need to post the information about your compiler/IDE version number!
    4. Post the information about your computer OS; Windows version and 32 bit or 64 bit.
    I know nothing about the Watcom compiler/IDE.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The data is possibly in an array (idList) but I don't really know how to tell what is actually stored in the array.
    But...

    > I actually have 75% of if it done ... I can enter in the particular number that I want .. ie 514
    > and get the info on the screen .. so "514 Test User 1"
    I would suggest you look really closely at how you got "Test User 1" out of the idList, because "2014/07/12 10:27:23" is going to be pretty close by.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    May be this helps a bit - CSV data manipulation - Rosetta Code
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 05-31-2009, 11:30 AM
  2. Reading pixel color data from screen
    By JJFMJR in forum Windows Programming
    Replies: 8
    Last Post: 08-22-2008, 12:27 PM
  3. Replies: 1
    Last Post: 10-22-2005, 05:28 AM
  4. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  5. data from a file instead of memory
    By bonkey in forum Windows Programming
    Replies: 5
    Last Post: 09-30-2002, 01:54 AM