473,385 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CSV file conversion...

Greetings all, i am trying to parse up a CSV Comma delmited file from
microsoft (gasp) excel. And then use that data to convert it to
another file format (.arff). in any event, i am having a bunch of
trouble trying to get the individual lines. If i open the .csv in
emacs then it appears that there are eoln characters (/n) however,
when i attempt to use iostream::getline(char*, int, char) it seems to
be failing on finding the end of line. im using the code:

ifstream input;
input.open("test_data.csv");
if (!input.good()) {
cerr << "Error opening\n";
exit(0);
}
char line[1024];
input.getline(line,1024,'\t'); //gets the first line in the file
int pos=0;
cout << "First Line: "<<line;
what its basically doing is reading past the first end of line and
reading exactly 1024 characters. Has anyone worked with csv files
before? Please let me know. Thanks!

Cheers,
Adam.
Jul 22 '05 #1
3 5119
On 22 Nov 2004 15:21:55 -0800, ff**@hotmail.com (Adam Balgach) wrote
in comp.lang.c++:
Greetings all, i am trying to parse up a CSV Comma delmited file from
microsoft (gasp) excel. And then use that data to convert it to
another file format (.arff). in any event, i am having a bunch of
trouble trying to get the individual lines. If i open the .csv in
emacs then it appears that there are eoln characters (/n) however,
when i attempt to use iostream::getline(char*, int, char) it seems to
be failing on finding the end of line. im using the code:

ifstream input;
input.open("test_data.csv");
if (!input.good()) {
cerr << "Error opening\n";
exit(0);
}
char line[1024];
input.getline(line,1024,'\t'); //gets the first line in the file
int pos=0;
cout << "First Line: "<<line;
what its basically doing is reading past the first end of line and
reading exactly 1024 characters. Has anyone worked with csv files
before? Please let me know. Thanks!

Cheers,
Adam.


I think your problem is a file format one, not a C++ one. There are
no tab characters ('\t') in a CSV (Comma Separated) file, although you
can have Excel export tab delimited files as well.

You need to look for ',', not for '\t'.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2
Hi,

"Adam Balgach" <ff**@hotmail.com> schrieb im Newsbeitrag
news:a5**************************@posting.google.c om...
[snip]
emacs then it appears that there are eoln characters (/n) however,
when i attempt to use iostream::getline(char*, int, char) it seems to
be failing on finding the end of line. im using the code:

[/snip]

DOS/Windows uses the old TTY-style for EOL: 0x0d0x0a (or vv); *ix uses '\n'.
So what you expect as EOL is not EOL.
Jul 22 '05 #3

You're getting input up to 1024 characters or until a tab character?
That's not necessarily the first "line" of the file. Also, what if a
line > 1024 chars?

How about using std::string? Something like:
std::string line;
std::getline( input, line, '\n' );
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eric | last post by:
Problem: -------- I'm trying to create an executable jar file. I can do so as long as I don't use the "package" statement in my source code. Once I put the package statement in I can't execute...
17
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was...
28
by: Colin JN Breame | last post by:
Hi, Fairly new to C. What is the best way to read a line (\n terminated) from a file? Ive looked at fscanf but was not sure which format specifier to use. (%s perhaps). Thanks Colin
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
7
by: Marcus Kwok | last post by:
I am working on a program that reads and processes large text files (on the order of 32 MB, so not too huge), so I wanted to add a progress indicator so I can estimate when it will finish. I just...
3
by: fazulu deen | last post by:
Hi all, For the following code : file_ptr = fopen("pass_fail.txt", "a"); // error line 393 fdisplay(file_ptr, "Test Passed"); fclose(file_ptr);
1
by: Neo007 | last post by:
**File Conversion from CSV format to Excel(.xsl) C# Detailed Requirement is : Requirements for File Conversion Application: 1.My Application must be command-line it should indicate success...
9
by: Matrixinline | last post by:
Hi All, Here is the problem char* memblock; std::ifstream file(sFileName, ios::in|ios::binary); if (file.is_open()) { size = file.tellg();
5
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a .Net web service that converts the MODCA files to tif or png file format. This web service runs on a 2003 server. This web service first copies the MODCA file to be converted to a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.