473,387 Members | 1,528 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,387 software developers and data experts.

Import csv file problem

Hello

Using the c file io functions if reading a csv file there is a problem if a
field contains an embedded carriage return. So I can check for apostrophe
pairs but processing does seem a bit of a struggle. Has anyone got a robust
algorithm or functions to use to reliably get a whole row of text from a csv
file even if some fields contain embedded carriage returns?

Angus
Sep 18 '06 #1
3 2303
Thought I better clarify:

Thought I better clarify:

Rules for a csv file are that each 'field' is separated by a comma (,) and
the end of each 'record' is terminated by a carriage return.

If a field contains a carriage return then you enclose the field in " and
" - quote marks. (Sorry apostrophe was wrong term to use).

So if I have this record:

1,1 The Avenue, New York, 345666,"hello in this field we have a carriage
return

more text here", 0233-444-7777,blue

If I use
char *fgets(char *s, size_t n, FILE *stream);

Then fgets gets to carriage return between two " "'s and I only half part of
the record.

I can obviously check if odd number of "'s in string and if so get to next
carriage return - but it does seem tricky getting it just right. I wondered
if anyone had come across this sort of thing before and how they got round
it?

Angus

"Someone" <no****@gmail.comwrote in message
news:ee*******************@news.demon.co.uk...
Hello

Using the c file io functions if reading a csv file there is a problem if
a
field contains an embedded carriage return. So I can check for apostrophe
pairs but processing does seem a bit of a struggle. Has anyone got a
robust
algorithm or functions to use to reliably get a whole row of text from a
csv
file even if some fields contain embedded carriage returns?

Angus


Sep 18 '06 #2
Someone wrote:
Thought I better clarify:
Why don't you first figure out which language you are working in. You
posted the same message to comp.lang.c.

Brian
Sep 18 '06 #3
On Mon, 18 Sep 2006 08:42:13 +0100 in comp.lang.c++, "Someone"
<no****@gmail.comwrote,
>Has anyone got a robust
algorithm or functions to use to reliably get a whole row of text from a csv
file even if some fields contain embedded carriage returns?
Hello, Angus. You still here? Are you still interested in this?

Sep 30 '06 #4

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

Similar topics

0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
6
by: bry | last post by:
Hi, I'm trying to do a dynamic import of a file that has no problems with it, that is to say I can import it normally, my sys.path is set to the right folder etc. but my dynamic import code is not...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
2
by: Tian | last post by:
I am writing a python program which needs to support some plug-ins. I have an XML file storing some dynamic structures. XML file records some class names whose instance needs to be created in the...
1
by: Learning Python | last post by:
An example in the book I didn't understood well two modules files recursively import/from each other in recur1.py,we have: x=1 import recur2 y=1
2
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
0
by: Victor Lin | last post by:
Hi, I got some problem with import. I have some python file that should be executed. Something like unit-test or other small tool. The project is not so small. So I want to separate these files...
0
by: Laszlo Nagy | last post by:
ohad frand wrote: So this is what you have: /1/tmp1.py /1/tmp2.py /2/tmp1.py /2/tmp2.py
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.