Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV reading program

Status
Not open for further replies.

croc

Technical User
Jan 8, 2002
12
0
0
GB
I am trying to write a program that will read a csv file from Excel, read a string two strings, combine them and compare with a third string.

I am OK with the combining and comparing the strings, what I would like to know is how do i go about reading the strings from a csv file?

Any help appreciated.

I use MS C++ 6 if there is an mfc class that will do this that anyone knows of.
 
I assume a .csv file is an excel file (or excel knows how to open it). If so, you may want to look into "automation" which can be found in the class wizard. When you insert the obl file, use the excelXX.obl file and you will have a bunch of new classes that add all the functionality of excel to your project. Dont know if this is what you were looking for.

Matt
 
Hmmm, I'll certainly look into doing it that way.
A .csv file is a comma seperated value file, basically a load of strings seperated by commas, I was just wondering if you or anyone else had tried to pull the strings from one of these before and if so how you went about it.
Just wondered what the simplest way would be to pull these strings from the file and how the program would interact with the file.
Thanks anyway.
 
Follow this pseudocode:

open the file
read first line

if not end of file, enter (or continue) loop
using strstr() or MFC CString.Find(), look for first comma
assign the first part of the string to a variable
replace the comma with a null
starting with the character after the null,
look for the second comma
assign the first part of the string to a second variable
replace the second comma with a null
assign the rest of line to a third variable
combine and compare variables
read next line
go to beginning of loop

close file
 
To all:

I didn't want to provide exact code in case this is a student project... I already gave too much. You just never know!
 
Cheers mate, I'm not a student but you've still done me a massive favour
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top